Editting a field in a table is becoming a headache for me as I cannot figure out simple solutions. My cause of the problem is not being found by my eyes. The updating of the database function is not working.
Here is my PHP for viewproducts.php
<?php
$result = mysql_query("SELECT * FROM products ")
or die(mysql_error()); ;
if (mysql_num_rows($result) == 0) {
echo 'There Arent Any Products';
} else {
echo "<table border='1' width=100%><tr><th>Product Name</th><th>Description</th><th>Price</th><th>Image</th><th>Edit</th><th>Delete</th>";
while($info = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $info['name']. "</td>";
echo "<td>" . $info['description']. "</td>";
echo "<td>£" .$info['price']." </td>";
echo "<td>" . "<img src='../getImage.php?id=" . $info['serial'] ."'/></td>";
echo '<td> <a href="edit.php?product_id=' . $info['serial'] . '">Edit</a></td>';
}
}
echo "</tr>";
echo "</table>";
?>
Here is my edit.php page:
<?php
$id = $_GET['product_id'];
$query = mysql_query("SELECT * FROM products WHERE serial = '$id'")
or die(mysql_error());
while($info = mysql_fetch_array($query)) {
echo "";
$name = $info['name'];
$description = $info['description'];
$price = $info['price'];
$picture = $info['picture'];
}
?>
<form action="editsuccess.php" method="post">
Product ID:<br/>
<input type="text" value="<?php echo $id;?>" name="serial" disabled/>
<br/>
Name:<br/>
<input type="text" value="<?php echo $name;?>" name="name"/>
<br/>
Description:<br/>
<input type="text" value="<?php echo $description;?>" name="description"/>
<br/>
Price:<br/>
<input type="text" value="<?php echo $price;?>" name="price"/>
<br/>
Picture:<br/>
<? echo'<img src="../getImage.php?id=' . $info['serial'] .'"/>'?>
</br>
<input type="submit" value="Update Product"/>
</form>
And finally here is my editsuccess.php page:
<?php
session_start();
require_once '../includes/db.php';
$id = $_REQUEST['product_id'];
$name = $_POST['name'];
$description = $_POST['description'];
$price = $_POST['price'];
$info = "UPDATE products SET name='$name', description ='$description', price ='$price' WHERE serial ='$id'";
mysql_query($info) or die ("Error: ".mysql_error());
echo "Database updated.";
?>
Any help guys?
It looks like you’re not passing
product_idto youreditsuccess.phppage. Try changing the first line of your<form>declaration inedit.phpto: