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.

If you do:

$sql="UPDATE recipe SET name='$name', bahan='$bahan', cara='$cara', id_category='$id_category' WHERE id='$id'";
echo $sql;

What query do you see ? You can then test this query e.g. in phpmyadmin.

Hi,

1) just change

echo "<select name=id_category value=''></option>";

to

echo "<select name=id_category><option value=''></option>";

2)

$sql="UPDATE recipe SET name='$name', bahan='$bahan', cara='$cara', id_category='$id_category' WHERE id='$id'";

try to use $_REQUEST/$_POST method eg: $_REQUEST[name]

3) It seems u didn't send any id from update.php to update_ac.php..change

<input align="center" type="submit" name="Submit" value="Submit" />

to

<input align="center" type="hidden" name="id" value="<?=$id;?>" />
<input align="center" type="submit" name="Submit" value="Submit" />

I hope this will help u..

to pretaeas:

i already test the sql statement, it doesn't get the value inserted..

to arajapandi:

your codes are really helpfull but as i said, the sql statement doesn't get the value inserted to be update.. how??

Please change the

$sql="UPDATE recipe SET name='$name', bahan='$bahan', cara='$cara', id_category='$id_category' WHERE id='$id'";

to

$sql="UPDATE recipe SET name='".$_REQUEST['name']."', bahan='".$_REQUEST['bahan']."', cara='".$_REQUEST['cara']."', id_category='".$_REQUEST['id_category']."' WHERE id='".$_REQUEST['id']."'";
print $sql;
exit;()

and post the result/query here..

This question has already been answered. Start a new discussion instead.