Jump to content

*SOLVED* annoying problem


corvyr

Recommended Posts

I get this message only on the page when I haven't done a search with it

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/aaronkor/public_html/beastpage.php on line 4
[/quote]

The error in question is on an included php file and as I said only appears until I use the search feature on the page. Below is a bit of the code where the error is happening

[code]$query = "SELECT count(*) as count FROM stats WHERE ".$_GET['mode']." LIKE '%$searchstring%'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$numrows = $row['count'];[/code]

Any help would be appreciated.
Link to comment
https://forums.phpfreaks.com/topic/6433-solved-annoying-problem/
Share on other sites

You should check for any possible MySQL errors before executing any subsequent MySQL related commands. You're getting that because there's an SQL syntax error on the query and you went ahead and still executed the fetch, which is wrong. Notice that "count" is a reserved word (for a function) in MySQL and you're "AS" is named the same. Change it to something else (recommended) or enclosed it in backtick marks.

[code]
$query = "SELECT count(*) as `count` FROM stats WHERE {$_GET['mode']} LIKE '%$searchstring%'";
$result = mysql_query($query) or die('SQL: ' . $query . ' Error: ' . mysql_error());
$row = mysql_fetch_array($result);
if (!$row) {
    echo 'No data';
} else {
    $numrows = $row['count'];
    echo 'Count: ', $numrows;
}
[/code]

FYI for all: This error is described in the FAQ page pinned at the top of the newbie topic area.
Link to comment
https://forums.phpfreaks.com/topic/6433-solved-annoying-problem/#findComment-23310
Share on other sites

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.