Jump to content

mysql_num_rows() error...


clonetrooper9494
 Share

Recommended Posts

I was told to use mysql_num_rows() to check if there was 1 row and then log the user in. But as you can see here http://clone-drone.net/login/ it says Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/clonedro/public_html/login/index.phtml on line 16 which is the line that says if(mysql_num_rows($sql_thing)==1) ... what is wrong? here is the code:

<html><head><title>Clone-Drone.net - Login</title></head><body bgcolor="#FFFFFF"><?phpinclude("http://clone-drone.net/php_scripts/navigate.php?extra=&link=");$u = (get_magic_quotes_gpc()) ? $_POST['user'] : mysql_real_escape_string($_POST['user']);$p = (get_magic_quotes_gpc()) ? $_POST['pass'] : mysql_real_escape_string($_POST['pass']);$con = mysql_connect('localhost','***********','************');mysql_select_db("clonedro_login", $con);$result = mysql_query("SELECT * FROM test_login WHERE user_name = '$u' AND user_password = '$p'");if(mysql_num_rows($result)==1){//Line 16echo "yay";//and someother code}else{echo "oh no!";}?><form action="http://clone-drone.net/login/index.phtml" method="post">Username:<input type="text" name="user"><br>Password:<input type="password" name="pass"><br><input type="submit" name="submit" value="Login"></form></body></html>

Link to comment
Share on other sites

I see nothing immediately wrong with your code, however, you could do a bit more to check and make sure that there are things set before you assume they are.

<html><head><title>Clone-Drone.net - Login</title></head><body bgcolor="#FFFFFF"><?phpinclude("http://clone-drone.net/php_scripts/navigate.php?extra=&link=");if(sizeof($_POST)>0){$u = (get_magic_quotes_gpc()) ? $_POST['user'] : mysql_real_escape_string($_POST['user']);$p = (get_magic_quotes_gpc()) ? $_POST['pass'] : mysql_real_escape_string($_POST['pass']);if(strlen($u)<3 OR strlen($p)<1){   die("Uesr data not submited");}$con = mysql_connect('localhost','***********','************');mysql_select_db("clonedro_login", $con);$result = mysql_query("SELECT * FROM test_login WHERE user_name = '$u' AND user_password = '$p'") or die(mysql_error());if(mysql_num_rows($result)==1){//Line 16echo "yay";//and someother code}else{echo "oh no!";}}//End if sizeof($_POST) if?><form action="http://clone-drone.net/login/index.phtml" method="post">Username:<input type="text" name="user"><br>Password:<input type="password" name="pass"><br><input type="submit" name="submit" value="Login"></form></body></html>

Link to comment
Share on other sites

Ok, I found the problem... it was a simple problem...in my code:

$result = mysql_query("SELECT * FROM test_login WHERE user_name = '$u' AND user_password = '$p'") or die(mysql_error());if(mysql_num_rows($result)==1){//Line 16

it is different than my SQL DB...

$result = mysql_query("SELECT * FROM test_login WHERE username = '$u' AND password = '$p'") or die(mysql_error());if(mysql_num_rows($result)==1){//Line 16

it said user_name instead of username

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...