Orionsbelter Posted September 2, 2011 Share Posted September 2, 2011 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'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/246239-object-of-class-stdclass-could-not-be-converted-to-string/ Share on other sites More sharing options...
xyph Posted September 2, 2011 Share Posted September 2, 2011 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'] Quote Link to comment https://forums.phpfreaks.com/topic/246239-object-of-class-stdclass-could-not-be-converted-to-string/#findComment-1264590 Share on other sites More sharing options...
MasterACE14 Posted September 2, 2011 Share Posted September 2, 2011 you have a space in here that you shouldn't: '$cart-> prodID' should be '$cart->prodID' Because with that space it is being read as a string. Quote Link to comment https://forums.phpfreaks.com/topic/246239-object-of-class-stdclass-could-not-be-converted-to-string/#findComment-1264591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.