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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

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.