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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_num_rows() not working 1

Status
Not open for further replies.

ljCharlie

IS-IT--Management
Joined
Apr 21, 2003
Messages
397
Location
US
Please help. This is what I have in my PHP code and it kepting giving me error.

<?PHP
//************ Variable Declaration ***************************************************
$sbSubmit = $HTTP_GET_VARS[&quot;btnSubmit&quot;];
$txtUsrName = $HTTP_GET_VARS[&quot;txtUserName&quot;];
$txtUsrPassword = $HTTP_GET_VARS[&quot;txtPassword&quot;];
$self = $HTTP_SERVER_VARS['PHP_SELF'];
//************Testing and Find Records**************************************************
$db = mysql_connect(&quot;tsevneeglauj&quot;, &quot;lorcz&quot;, &quot;alcy123&quot;); //connect to database
if ($txtUsrName == &quot;&quot; || $txtUsrPassword == &quot;&quot;){
echo &quot;User name: &quot;.$txtUsrName & &quot; password: &quot;.$txtUsrPassword;
echo &quot;Please enter either your user name and/or password!&quot;;
exit;
}
elseif(!$db) {
echo &quot;Error: Could not connect to database. Please try again later.&quot;;
exit;
}

mysql_select_db(&quot;losociety&quot;, $db);
$query = &quot;SELECT * FROM users WHERE (usrName LIKE $txtUsrName AND usrPassword == $txtUsrPassword)&quot;;
$result = mysql_query($query, $db);
$num_results = mysql_num_rows($result);
echo &quot;Num results: &quot;.$num_results.&quot;<br>&quot;;
if ($num_results ==0){
echo&quot;Either your password and/or user name is incorrect. Plesae try again.&quot;;
exit;
}
else{
require(&quot;resultTable.inc&quot;);
}
?>

The error is:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\ on line 35

Many thanks in advance!

ljCharlie
 
This line needs some quotes:
[tt] $query = &quot;SELECT * FROM users WHERE (usrName LIKE '$txtUsrName' AND usrPassword == '$txtUsrPassword')&quot;;[/tt]
I added the red ones.

//Daniel
 
1) When making SQL queries it is necesary to quote string literals (red single quotes):
$query = &quot;SELECT * FROM users WHERE (usrName LIKE '$txtUsrName' AND usrPassword = '$txtUsrPassword')&quot;;

2) SQL does not have the = as assignment operator, therefore == is not not necessary.

3) Your error is in the SQL statement. It produces an invalid result set. mysql_num_rows() then throws an error with that invalid set.
 
Whoops, I missed the double equal signs. Good catch DRJ478.

//Daniel
 
Thank you very very much you guys! It works! I'm greatly appreciate your help.

ljCharlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top