VickP07
09-27-2011, 06:09 PM
Hey guys,
So i am populating a php page with some data from the DB but i am trying to allow the user to enter in data to update a field in a table of my DB, but it isn't working.
Here is my code for the update:
<?php
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "Peters_restaurantDB");
$id = $_GET['id'];
$sql = "
SELECT id, name, description, preptime, totaltime, rating
FROM recipes
WHERE id = $id;
";
if( $_POST )
{
$rate = $_POST['rating'];
$sql5 = "
UPDATE recipes
SET rating = $rate
WHERE id = $id;
";
$result5 = mysql_query( $sql5 )
or die( "Insert failed ($sql5): " . mysql_error() );
}
?>
HEre is where i am allowing the user to enter in a new "rating" for the recipe being displayed on the page (ShowRecipe.php):
<form action="ShowRecipe.php?id=<?echo $id?>" method="POST">
<table>
<tr><td align="right">Enter new Rating: </td>
<td><input type="text" name="rating"></td>
</tr>
</table>
<input type="submit" value="Update Rating">
</form>
Right now the problem is that after i enter in a new raiting in the textbox and click submit.....the page refreshes itself but the update is not working and the data is not being changed.
So i am populating a php page with some data from the DB but i am trying to allow the user to enter in data to update a field in a table of my DB, but it isn't working.
Here is my code for the update:
<?php
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "Peters_restaurantDB");
$id = $_GET['id'];
$sql = "
SELECT id, name, description, preptime, totaltime, rating
FROM recipes
WHERE id = $id;
";
if( $_POST )
{
$rate = $_POST['rating'];
$sql5 = "
UPDATE recipes
SET rating = $rate
WHERE id = $id;
";
$result5 = mysql_query( $sql5 )
or die( "Insert failed ($sql5): " . mysql_error() );
}
?>
HEre is where i am allowing the user to enter in a new "rating" for the recipe being displayed on the page (ShowRecipe.php):
<form action="ShowRecipe.php?id=<?echo $id?>" method="POST">
<table>
<tr><td align="right">Enter new Rating: </td>
<td><input type="text" name="rating"></td>
</tr>
</table>
<input type="submit" value="Update Rating">
</form>
Right now the problem is that after i enter in a new raiting in the textbox and click submit.....the page refreshes itself but the update is not working and the data is not being changed.