I am trying to build up a system where I have web pages content generated by a user in a form, saved in a database, make a list of all the pages existing in the database and by clicking on that list editing the desired page.
The only thing that is not working is the editing part. It seems that I cannot grab the data from the database because when I click on a page to edit, the "template" has nothing in the forms.
Here is the code:
Page with the list of pages existing on the database:
<?php
require_once "../scripts/conector.php";
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = preg_replace('/[^0-9]/', "", $_GET['pid']);
}
$sqlCommand = "SELECT id, producent FROM pages WHERE showing='1' ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die('Error: ' . mysqli_error($myConnection));
$producentnamn = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$producent = $row["producent"];
$producentnamn .= '<a href="edit_page.php?pid=' . $pid . '">' . $producent . '</a>';
}
mysqli_free_result($query);
?>
<form id="form1" name="form1" method="post" action="edit_page.php">
<input type="submit" name="button2" id="button2" class="botao" value="Redigera" />
<input name="pid" type="text" id="pid" value="<?php echo $producentnamn; ?>"/>
</form>
edit_page.php
<?php
$pid = ereg_replace("[^0-9]", "", $_POST['pid']);
include_once "../scripts/conector.php";
$sqlCommand = "SELECT pagetitle, linklabel, evenemang, presentation, producent, pagebody, mapa FROM pages WHERE id='$pid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$pagetitle = $row["pagetitle"];
$linklabel = $row["linklabel"];
$evenemang = $row["evenemang"];
$presentation = $row["presentation"];
$producent = $row["producent"];
$pagebody = $row["pagebody"];
$mapa = $row["mapa"];
}
mysqli_free_result($query);
?>
<label>Map</label>
<textarea name="mapa" id="mapa"><?php echo $mapa; ?></textarea>
So, what am I doing wrong here? Many thanks in advance!