Jump to content

PHP mysql_fetch_row() supplied argument is not valid

Recommended Posts

Can i get some help with this error, thanks. What is the problem? Is it that $result is giving it bad data or what?[error] PHP Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/www/file1.php on line 131, referer: http://example.com/file2.html126 // find input from MySQL127 $query = 'SELECT response, preceed FROM $assignedtable';128 $result = mysql_query($query);129 // gonecount counts the line were on in the MySQL DB130 $gonecount = 0;131 while(list($response,$preceed)= mysql_fetch_row($result)) {132 for($g=0; $g<$gonesize; $g++){133 if ($response == $gone[$g]) {134 $isgone[$g] = 1;135 $locgone[$g] = $gonecount;136 }137 }138 $gonecount++;139 }

Link to post
Share on other sites

I'm no expert in MySQL, but does it allow actually resolve any variable references?The way you have written it, $assignedtable is a variable that MySQL must resolve on its own, not a PHP variable, and again, I don't know if MySQL can do that, so this may be a valid query. If indeed you wanted to use a PHP variable there, you need to use double quotes instead of single ones, or concatenate the variable instead of embedding it. I think double quotes is the more elegant way i.e.

$query = "SELECT response, preceed FROM $assignedtable";

Link to post
Share on other sites
The variable is resolved in PHP first, at least in my queries things like that work ok.
Not if you use single quotes they don't. Single quotes disable variable resolution in strings. It's only available with double quotes. Unless the PHP MySQL extension is actually responsible of resolving the variable before sending the query to the MySQL engine, then what the MySQL engine receives is exactly what we see, not what we would like the query to resolve to.
Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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