...

View Full Version : Title Problem in Database



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

abduraooft
10-17-2009, 03:14 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 Please explain that 'weird problem'

Dshah
10-17-2009, 03:20 PM
ok thanks... here is the detail...

i have a page displaying all the products name and price from database and on same page i have edit button to update the price

echo "$id : $title - <a href='manager.php?cmd=edit&id=$id'>Edit</a>";

when i click it it will open that item on same page there i have option to edit the price:

<b>Enter New Price:<b/><INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=4><br>

and after that submit button:

<div style="margin:10px 0 0 120px;"><input type="submit" name="submit" value="submit"></div>

when i click submit it runs :

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>";
}
in booklist database i have 20 products . for example if i will update the price of ID16 item it will change the price and title of ID20 .... so confuse sir any help

Thanks

Edit: ok here was the problem in my query
$sql = "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
i was using all three fields

now what is happenning its not updating the price
$sql = "UPDATE booklist SET price='$price' WHERE id=$id";

abduraooft
10-17-2009, 03:32 PM
Try

$id=(int) $_POST["id"];
$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) or die(mysql_error());

Dshah
10-17-2009, 03:38 PM
IT WORKS...thank you very much sir

Best wishes



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum