Jump to content

Object of class stdClass could not be converted to string


Orionsbelter

Recommended Posts

why do i keep getting this error from line 7?

 

Object of class stdClass could not be converted to string

<?php
include_once"../includes/db_connect.php";
$item_number="2";
$custom="54298";
$query=mysql_query("SELECT `prodID`, `quanity` FROM `cart` WHERE `sessID`='$custom'") or mysql_error();
while($cart=mysql_fetch_object($query)){
mysql_query("INSERT INTO  `orderItems` (  `id` ,  `orderInfoID` ,  `productID` ,  `quanity` ) VALUES ('',  '$item_number',  '$cart-> prodID',  '$cart->quanity');");
}
mysql_query("UPDATE `cart` SET `show`='1' WHERE `sessID`='$custom'");

?>

 

Don't use a query in a loop. Instead, build a query like

 

INSERT INTO `table` ( `col1`, `col2` ) VALUES ( 'data1a', 'data1b' ), ( 'data2a', 'data2b' ), ( 'data3a', 'data3b' ) etc...

 

And rather than deal with an object, just use $cart=mysql_fetch_assoc($query) and your values will be $cart['prodID'] and $cart['quanity']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.