Jump to content


This topic is now archived and is closed to further replies.


*SOLVED* annoying problem

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

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.

Share this post

Link to post
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.

$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;

FYI for all: This error is described in the FAQ page pinned at the top of the newbie topic area.

Share this post

Link to post
Share on other sites
Fixed it just before I noticed the reply, had the include() in the wrong spot it seems.

Share this post

Link to post
Share on other sites


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.