update.php
<?php
include 'recipe2db.php';
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM recipe WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array ($result);
?>
<form name="form1" method="post" action="update_ac.php">
<table border="1" cellspacing="0" cellpadding="3">
<thead>
<th>name</th>
<th>ingredient</th>
<th>how to cook</th>
<th>category</th>
</thead>
<tr>
<td> <input name="name" type="text" id="name" value="<? echo $rows['name']; ?>" /> </td>
<td> <input name="bahan" type="text" id="bahan" value="<? echo $rows['bahan']; ?>"></td>
<td><input name="cara" type="text" id="cara" value="<? echo $rows['cara']; ?>"></td>
<td>
<?php
$query="SELECT id_category, category_name FROM category";
$result = mysql_query ($query);
echo "<select name=id_category value=''></option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id_category]>$nt[category_name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?></td>
</tr>
</table>
</td>
<input align="center" type="submit" name="Submit" value="Submit" />
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>
update_ac.php
<?php
include 'recipe2db.php';
// update data in mysql database
$sql="UPDATE recipe SET name='$name', bahan='$bahan', cara='$cara', id_category='$id_category' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='home.php'>HOME</a>";
}
else {
echo "ERROR (".mysql_errno()."):";
echo mysql_error();;
}
?>
after i submit the updated data, it successful but it doesnt update in the database. help me to find out why?
i already check for many times, and all the variable are correct.