Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: argument is not a valid MySQL result resource <=-- Help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi All,
I'm having trouble with a simple command. I have two PHP pages, one submits data to the other for a search on a MySQL database. The first is a basic form, so the code is correct on that one, it's the second that is generating the error. Here is a summary of the code... any hints?

$link = mysql_connect($DBhost,$DBuser,$DBpass);
mysql_select_db("$DBName",$link);
$sqlquery = "SELECT * FROM $table WHERE usrname = $usrname";
$result = mysql_query($sqlquery,$link);
$num_rows = mysql_fetch_row( $result ); <=--- Error is generated on this line

When running the code, the following error is generated:

Warning: Supplied argument is not a valid MySQL result resource in d:\html\php\results.php on line 17

I have checked the PHP.net web site for the arguments on this command, and they're correct as far as I can tell... yet the error is still appearing... Any help would be much appreciated.

Jon
 
First, you should be checking each mysql statement for errors - with your code the way it is now, you don't really know what the problem is. Each mysql statement should have some return code that it returns if an error occurs.

Second, your select - you should
1. use addslashes for any string variables used in
the WHERE or ORDER BY, and
2. surround all $-variables used with single quotes,
like:

$usrname = addslashes($usrname);
$sqlquery = &quot;
SELECT *
FROM $table
WHERE usrname = '$usrname'
&quot;;

The single quotes may solve your problem, but you should still check each statement for errors.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top