I’m using this exact code on two pages, and on one of the two it blows up. Both pages have the exact same user/pass/host/db links (same header), and the query returns a record if I print the $command and paste into Sequel Pro.
Here is the query:
$command = "SELECT ID,Location,OriginalLocationID FROM locations WHERE FloorID='".$_SESSION['FloorID']."' ORDER BY ID DESC LIMIT 1";
echo $command;
$query = mysql_query($command);
while($results = mysql_fetch_row($query))
{
$_SESSION['LocationID']=$results[0];
$_SESSION['LocationName']=$results[1];
$_SESSION['OriginalLocationName']=$results[2];
}
The error that I’m getting is:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
As a note, the SESSION[‘FloorID’] is set when you click the link, so that’s not blank or broken. Any idea what I’m doing wrong, or why it would work on one page and not another?
Also – yes I’ve Googled, it isn’t an empty error or syntax or anything, because as I mentioned it works perfectly on another page.
This indicates the the query itself failed, which may happen because of invalid syntax or because the database connection itself has not been established.
You must perform error handling before calling
mysql_fetch_row(), and upon failure, usemysql_error()to identify the error cause.