Forum Moderators: coopster

Message Too Old, No Replies

Problem with this script

Multiple update

         

Axheladini

10:52 am on Oct 13, 2007 (gmt 0)

10+ Year Member



Hi i am using this script to do Multiple update with php and Mysql.
It works great with all browsers but not with IE , please any help?

$size = count($_POST['Quantity']);

$_SESSION['id']=session_id();
$i = 0;
while ($i < $size) {
$cid= $_POST['Cartid'][$i];
$product= $_POST['ProductID'][$i];
$productname=$_POST['ProductName'][$i];
$quantity= $_POST['Quantity'][$i];
$Price= $_POST['Price'][$i];
$TotalPrice= $_POST['TotalPrice'][$i];

echo $productname;

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$query = "UPDATE cart SET Quantity ='$quantity', TotalPrice=$Price*$quantity where ProductID='$product' and CartID='$cid' ";
mysql_query($query);

if(!query)

echo "Query lesh";

$i++;

}

header("Location: view_cart.php");
exit;

ayushchd

11:07 am on Oct 13, 2007 (gmt 0)

10+ Year Member



Hi.

Firstly change this :

$query = "UPDATE cart SET Quantity ='$quantity', TotalPrice=$Price*$quantity where ProductID='$product' and CartID='$cid' ;";

That is, a semi-colon after your query.

Then Change this :
mysql_query($query);

if(!query)

echo "Query lesh";

to :

if (!mysql_query($query)) {

echo mysql_error();

}

Find out the error in IE first.
And then we can go on further solving it.

ayush

Axheladini

11:16 am on Oct 13, 2007 (gmt 0)

10+ Year Member



first of all thanks for telling this code

if (!mysql_query($query)) {

echo mysql_error();

because i was not able to find what is happening
second: this is the error that i get

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*4 where ProductID='2'' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*8 where ProductID='1'' at line 1

ans i don't know how to fix it

ayushchd

11:25 am on Oct 13, 2007 (gmt 0)

10+ Year Member



Do this while defining variables at the top :

$tprice = $Price*$quantity;

And then change your query to this :

$query = "UPDATE cart SET Quantity ='$quantity', TotalPrice='$tprice' where ProductID='$product' and CartID='$cid';";

Should work.

If not, paste the error you get.

ayush

Axheladini

11:33 am on Oct 13, 2007 (gmt 0)

10+ Year Member



Thanks
its working great, really thanks
i don't know why thinks with error sometimes are working with Firefox and