Im working on a small PHP project for learning purpose. i want to retrieve saved data from a MySQL data base and let the user edit it using a HTML form. im able to retrieve the data and display in the text boxes. problem is when the form is submitted data is not updating. here is the code i got so far. file is made to update it self. if anyone can tell me where did i go wrong it will be most appreciated. thank you.
<?php
include ("header.php");
include ("../db.php");
$catname = $_POST['catname'];
$catdisc = $_POST['catdisc'];
$id = $_GET['id'];
if (isset($id))
{
$query = "SELECT * FROM categories WHERE catid='$id'";
$result= mysql_query($query) or die ('Mysql Error');
}
while($row = mysql_fetch_array($result)){
$cname = $row['catname'];
$cdisc = $row['catdisc'];
}
$result= "UPDATE categories SET catname='$catname', catdisc='$catdisc' WHERE catid='$id'"
or die ('Error Updating');
?>
<h1>Edit Categories</h1>
<form method="post" action="edit_cat.php?id=<?php echo $id;?>">
Category Name: <input type="text" name="catname" value="<?php echo $cname;?>"><br/>
Category Discription: <TEXTAREA NAME="catdisc"ROWS="3" COLS="25"><?php echo $cdisc;?></TEXTAREA><br/><br/>
<input type="submit" value="Update Category"/>
</form>
<?php
include ("footer.php");
?>
1 Answer