Jump to content

mysql_fetch_row() expects parameter 1 to be resource, boolean given


Triple_Nothing

Recommended Posts

Howdy y'all. I'm rather good at troubleshooting my errors, especially when I know what the error means. That way I at least have an idea of what I am looking for. This one has me at a loss...

Error:

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in ...

And the area it references is:

$carrier = mysql_fetch_row(mysql_query("SELECT `CarrierName` WHERE `CarrierID` = " . $myArray[$i][6]));

The $myArray[$i][6] holds a single digit number for a value.

The error means that the query failed due to an error. It does not mean that the query matched zero rows. One of the possible errors would be a sql syntax error if $myArray[$i][6] is empty or non-existent.

 

You should form your query string in a variable, such as $query, and then echo the query so that you can see what it actually contains.

 

You should not nest mysql_fetch_row(mysql_query()) functions as that prevents you from testing if the query executed without errors before you attempt to fetch data from a non-existent result resource (a query that matches zero rows returns a result resource that contains zero rows.) You would then also be able to use mysql_num_rows() to determine how many rows the query returns when it actually executes without errors.

 

Edit: Using some error checking and error reporting logic on the query, would have pointed out where in the query to look.

 

 

 

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.