Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
mysql error

Posted by Chris_Isaac (Chris Isaac), 25 July 2003
Hi  sorry, I'm back, I keep getting the following error

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

from the snipit of code below, I can't understand why, its working for the other searches.  

I've also checked the values for $name and $town and they both contain the correct information.

I've also tried substituting the command for mysql_fetch_row, but the error came up again.  Am I doing anything obviously wrong?


           elseif ($name) {
     $q = "Select * from hotel,locations where hotel.location =      and rlike \"$name\" and rlike \"$town\"";
     $res = mysql_query($q);
     $html = "<table width=90% border=1>";
     $cheapshown = 0;
     $nrow = 0;
     while ($row = mysql_fetch_array($res)) {

Posted by admin (Graham Ellis), 26 July 2003
Nothing obvious, no.  

Is it possible that you variables could contain " characters?  (Solution - use addslashes or quotemeta function).

Is it possible that a field or table name is mis-spelt?

Is it possible that you failed to mysql_connect or mysql_select_db?

Have you done several mysql_connect-s in your program, and you're sending your query to the wrong connection?

If it's not quickly apparent which of the above is the problem,  print out the values in $town and $county and run the equivalent of the mysql_query call manually in a mysql client - that will give you further evidence from which to analyse the problem.

By the way - you should always check your return code from mysql_query, and if it's false exit gracefully ("Database tables not available at present") rather than crash out at the next call. You might be planning to add that code once you have the thing working, but it can be helpful at quite an early stage if the thing keeps aborting / doing funny things in the way your code is doing.

Posted by Chris_Isaac (Chris Isaac), 26 July 2003
I've fixed it, the problem was with my if statement!  I needed to check for $name and $town!

Thanks anyway


This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho