Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: $row = mysql_fetch_row($result);

Status
Not open for further replies.

tshey

Technical User
Dec 28, 2005
78
AU
I have this piece of code to check if an item already exists in the users cart table.
Code:
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
		$row = mysql_fetch_row($result);
		$numRows = $row[0];
		
		if($numRows == 0)
		{
However this particular piece of code
Code:
$row = mysql_fetch_row($result);
is coming back with an error of Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result Can anyone help me, I dont understand it!

Code:
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
		$row = mysql_fetch_row($result);
		$numRows = $row[0];
		
		if($numRows == 0)
		{
 
That probably means that the query is coming back without any rows, therefore $result is false. Meaning no rows in your table match the criteria yu specified in your select statement.

When $result is false, it can't be used by mysql_fetch_row and therefore it generates that particular error.

You should check if $result actually has results before before you try to use it with mysql_fetch_row or any other mysql_function that uses a result.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Actually, if the $result would return 0 rows, that would still be a correct result and you could still retrieve the data. However, you have an error in your SQL. First thing, you should add is some debugging:
Code:
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId") or die ('Error in query: ' . mysql_error());
If that does not give you a clue, print out the query:
Code:
echo "select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
and paste it in your favourite database admin and run it there to see what it returns. Sooner or later you will see that your query is not returning what you're expecting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top