Hello DaniWeb Community! I am trying to create a web page that utilizes Ajax and PHP to connect to my mySql database and look up a username and password. You have all most likely seen the web page that has the template code on it: http://www.phpeasystep.com/workshopview.php?id=6
This code is nice as a template, but I cannot get one of the functions to work: mysql_num_rows($result); . I get this message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/thatcom1/public_html/drafts/HaxMe/DatabaseAjaxLogin/processLogin.php on line 31 . I have looked it over, there is nothing wrong with that perticular line of code or any others around it. the source for my page is:


//Will return welcome message if login is correct, incorrect message if incorrect and set a cookie. 
$host="localhost"; // Host name
$username="blablabla"; // Mysql username
$password="blablabla"; // Mysql password
$db_name="blablabla"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form

// To protect MySQL injection. I took this out for debugging. 
/*$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM 'users' WHERE userName='$myusername' and passHash=md5('$mypassword')";
// Mysql_num_row is counting table row
echo "count is: ";
echo $count;
// If result matched $myusername and $mypassword, table row must be 1 row
echo "<font color=\"green\">Correct Password!</font>";
else {
echo "<font color=\"red\">Incorrect! $mypassword </font>";


This is part of an Ajax login page, the site that is running this code can be found here:
If you need the ajax page, tell me.
again, that is my webpage if you need to use it for testing.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result

It means query did not execute successfully.

You are using single quotes around table name which is not correct. Either use back tick ` around the table name or don't use anything at all e.g.

$sql="SELECT * FROM `users` WHERE userName='$myusername' and passHash=md5('$mypassword')";


$sql="SELECT * FROM users WHERE userName='$myusername' and passHash=md5('$mypassword')";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.