Hello again.
Im still having problems with my mysql update script.
The script below is supposed to fill the form with values based on wich row I clicked on the view page, another page wich lists out all the rows and columns of the mysql table. This is where id comes in. When the rows are filled with the values the user (myself) should be able to change/update the values befor I click on update. Then the updated values should be inserted into that spesific row. This is not happening now. Note that I for now have removed the update part and replaced it with print_r just to simplify the script for myself.
With the WHERE id=$id part the script correctly fills the values from the mysql table into the form. But when I click on update the script doesnt return any values at all. Only a blank page. If I remove the WHERE id=$id part the script only fills out the form with the first mysql table row, but when I click on update it returns the entered values correctly.
Please look away from the security issues for now.
Any idea what Im doing wrong here ?
Any help is greatly apreciated.
<?php
echo "<a href=./>Home</a><br>";
$id = $_GET['id'];
$connect = mysqli_connect("localhost","user","pass","db") or die(mysql_error());
$query = mysqli_query($connect, "SELECT filename,dato,size,spoken,speaker,dialect,project,gender FROM pdb WHERE id=$id") or die (mysqli_connect_error());
$fetch_data = mysqli_fetch_array($query, MYSQLI_ASSOC);
if (!$_POST) {
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<table border='1'>";
foreach($fetch_data as $key => $val) {
echo "<tr><td>".$key."</td><td><input type='text' name='".$key."' value='".$val."'></td></tr>";
}
echo "</table>";
echo "<input type='submit' value='Update'>";
echo "<input type='button' onclick='history.go(-1)' value='Cancel'>";
echo "</form>";
}
else {
print "<pre>";
print_r($_POST);
print "</pre>";
}
mysqli_close($connect);
?>