Jump to content

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


kamran193

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.

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.