0

The result of 'mysql_query' is a resource, right? Then why am I getting this error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given on this piece of code? CODE:

$con = mysql_connect("localhost","root")or die("NO");
mysql_select_db($db_name,$con)or die("Not good");


$usernames=mysql_query("SELECT * FROM user_info WHERE Username='$user' AND Password='$password'");


$count=mysql_num_rows($usernames);

if($count==1){session_register("user");session_register("password");header("location:Login_Success.php");}
else{echo "<p style='color:red'>Wrong username or password!</p>";}

Also, I have a problem with my if...else statement. The else code appears before the if's.

Andy G
  • 19,232
  • 5
  • 47
  • 69

1 Answers1

1

your mysql connect should be like that

     mysql_connect('localhost', 'root', 'mysql_password');
                                        ^^^^^^^^^^^^^^^^----you forgot this

you forgot password.

and you should not use mysql but instead use PDO or MYSQLI.

if you use mysql_error() you can see whats wrong easilly . like that:

 $con = mysql_connect("localhost","root","mysql_password")or die(mysql_error()); 
echo_Me
  • 37,078
  • 5
  • 58
  • 78