Dshah
10-17-2009, 03:02 PM
hi to all , i have a weird problem when i try to edit my price from database via my php file it is changing other item title and price in database, please help
here is the code of my php file:
<?php ob_start() ;
if(!isset($cmd))
{
//displaying all products on the page with title and price
$result = mysql_query("select * from booklist order by id");
echo'<center><h3>Product List</h3></center>';
//run the while loop that grabs all
while($r=mysql_fetch_array($result))
{
$title=$r["title"];// title
$id=$r["id"];// id
echo "$id : $title - <a href='manager.php?cmd=edit&id=$id'>Edit</a>";
echo "<br>";
}
}
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM booklist WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="manager.php" method="post">
<input type="hidden" name="id" value="<?php echo $myrow["id"] ?>">
<h3>Please Enter New Price For the Unit:</h3>
<b>Title:</b><?php echo $myrow["title"] ?><br />
<b>Message:</b><? echo $myrow["body"] ?><br />
<b>Enter New Price:<b/><INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=4><br>
<input type="hidden" name="cmd" value="edit">
<div style="margin:10px 0 0 120px;"><input type="submit" name="submit" value="submit"></div>
</form>
<?php }
if ($_POST["submit"])
{
$title = $_POST["title"];
$body = $_POST["body"];
$price = $_POST["price"];
// Here i am having issue when i update it
$sql = "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
$result = mysql_query($sql);
echo "<br /><center><font color=\"red\">The Product Price Has been Updated. </font></center>";
}
}
ob_flush() ; ?>
Thanks for any help
here is the code of my php file:
<?php ob_start() ;
if(!isset($cmd))
{
//displaying all products on the page with title and price
$result = mysql_query("select * from booklist order by id");
echo'<center><h3>Product List</h3></center>';
//run the while loop that grabs all
while($r=mysql_fetch_array($result))
{
$title=$r["title"];// title
$id=$r["id"];// id
echo "$id : $title - <a href='manager.php?cmd=edit&id=$id'>Edit</a>";
echo "<br>";
}
}
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM booklist WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="manager.php" method="post">
<input type="hidden" name="id" value="<?php echo $myrow["id"] ?>">
<h3>Please Enter New Price For the Unit:</h3>
<b>Title:</b><?php echo $myrow["title"] ?><br />
<b>Message:</b><? echo $myrow["body"] ?><br />
<b>Enter New Price:<b/><INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=4><br>
<input type="hidden" name="cmd" value="edit">
<div style="margin:10px 0 0 120px;"><input type="submit" name="submit" value="submit"></div>
</form>
<?php }
if ($_POST["submit"])
{
$title = $_POST["title"];
$body = $_POST["body"];
$price = $_POST["price"];
// Here i am having issue when i update it
$sql = "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
$result = mysql_query($sql);
echo "<br /><center><font color=\"red\">The Product Price Has been Updated. </font></center>";
}
}
ob_flush() ; ?>
Thanks for any help