kamran193 Posted January 4, 2012 Share Posted January 4, 2012 i am having problem with this error, could you please help me function cart () { foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query("SELECT ProductID, Name, Price FROM product WHERE ProductID = '".mysql_real_escape_string((int)$productid."'")); while ($query_row = mysql_fetch_assoc($query)) { $sub = $query["Price"]*$Value; echo $query["Name"]. ' x ' .$value. ' @ '.$query["Price"]. ' = '.$sub.'<br />'; } } } else { echo "<p>Your Shopping Basket is empty</p>"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/254378-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in/ Share on other sites More sharing options...
Pikachu2000 Posted January 4, 2012 Share Posted January 4, 2012 Let's see, you give the result of mysql_query() to mysql_fetch_assoc() and you get that error. Now, according to the manual, mysql_query() returns either a query result resource on successful execution, or a boolean FALSE on failure, so that must mean the query is failing. mysql_error should provide some insight. Quote Link to comment https://forums.phpfreaks.com/topic/254378-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1304355 Share on other sites More sharing options...
requinix Posted January 5, 2012 Share Posted January 5, 2012 Look at where you put your parentheses. They aren't all in the right places. And you don't need to mysql_real_escape_string() a number. And you don't need to use quotes in the query if they're around numbers. Quote Link to comment https://forums.phpfreaks.com/topic/254378-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1304372 Share on other sites More sharing options...
kamran193 Posted January 5, 2012 Author Share Posted January 5, 2012 The error is occurring on this line while ($query_row = mysql_fetch_assoc($query)) { and on which line is the parentheses incorrect Quote Link to comment https://forums.phpfreaks.com/topic/254378-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1304376 Share on other sites More sharing options...
requinix Posted January 5, 2012 Share Posted January 5, 2012 The one above that. Quote Link to comment https://forums.phpfreaks.com/topic/254378-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1304379 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.