Jump to content

mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in


Recommended Posts

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>";	
					}
				}
			}

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.