clonetrooper9494 Posted February 6, 2008 Share Posted February 6, 2008 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 More sharing options...
jhecht Posted February 6, 2008 Share Posted February 6, 2008 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 More sharing options...
Synook Posted February 6, 2008 Share Posted February 6, 2008 acho, check mysql_error() to see whether there is an error with yoru query. Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted February 6, 2008 Author Share Posted February 6, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.