corvyr Posted April 2, 2006 Share Posted April 2, 2006 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. Quote Link to comment Share on other sites More sharing options...
toplay Posted April 3, 2006 Share Posted April 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
corvyr Posted April 3, 2006 Author Share Posted April 3, 2006 Fixed it just before I noticed the reply, had the include() in the wrong spot it seems. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.