Warning: mysql_num_rows() expects parameter 1 to be resourc

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat Mar 02, 2013 8:06 am

Warning: mysql_num_rows() expects parameter 1 to be resourc

Postby jopereira » Sat Mar 02, 2013 9:08 am

Code: Select all


$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="adad"; // 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("Não foi possível conectar à base de dados!");

// username and password sent from form

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

// Mysql_num_row is counting table row

// If result matched $myusername and $mypassword, table row must be 1 row


// Register $myusername, $mypassword and redirect to file "login_success.php"
else {
echo "Nome de utilizador ou senha incorrectos!";

what's the problem with this?

the error line is 27:

User avatar
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Warning: mysql_num_rows() expects parameter 1 to be reso

Postby simplypixie » Sun Mar 03, 2013 12:58 am

The error means that your query is failing (so there are no rows to count) so echo out your $sql and see what exact query it is trying to run on the database and make sure it is correct (if you think it looks correct then copy and paste into PHPMyAdmin and see what error you get there).

Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 8 guests