vasoftwaresolutions Posted March 12, 2008 Share Posted March 12, 2008 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 23 Does any know what that means.. here is my code <?php $host="localhost"; // Host name $username="pacifij1_blue"; // Mysql username $password="8336994895"; // Mysql password $db_name="pacifij1_blue"; // Database name $tbl_name="pilot"; // 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 signup form $callsign=$_POST['callsign']; $password=$_POST['password']; $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("callsign"); session_register("password"); session_register("first_name"); session_register("last_name"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- TemplateBeginEditable name="doctitle" --> <title>Loading</title> <!-- TemplateEndEditable --> <!-- TemplateBeginEditable name="head" --> <!-- TemplateEndEditable --> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/95726-php-login/ Share on other sites More sharing options...
monkeypaw201 Posted March 12, 2008 Share Posted March 12, 2008 Just as a recommendation for next time, don't put in your password and username replace it with "user" and "pass" or something similar (Thats how you get hacked ) Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490108 Share on other sites More sharing options...
vasoftwaresolutions Posted March 12, 2008 Author Share Posted March 12, 2008 Anything on why its not working? Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490116 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 Monkey is right though... Give me a second to look at it. Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490118 Share on other sites More sharing options...
vasoftwaresolutions Posted March 12, 2008 Author Share Posted March 12, 2008 that not my real login.. i just changed the password Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490119 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 Change: $count=mysql_num_rows($result); To: $count=mysql_numrows($result); Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490121 Share on other sites More sharing options...
ohdang888 Posted March 12, 2008 Share Posted March 12, 2008 ok so you're using sessions? If you are using sessions on every page of your site... then do this... the first and second lines should be... <? session_start(); session_destroy(); and then right before you do the session register, put "session_start();" before it... Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490122 Share on other sites More sharing options...
vasoftwaresolutions Posted March 12, 2008 Author Share Posted March 12, 2008 Change: $count=mysql_num_rows($result); To: $count=mysql_numrows($result); its giving me this now "Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 23" Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490124 Share on other sites More sharing options...
ohdang888 Posted March 12, 2008 Share Posted March 12, 2008 go back to what you had before and try the sessions... Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490126 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 Change: $count=mysql_num_rows($result); To: $count=mysql_numrows($result); its giving me this now "Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 23" Is that first set of code you gave us the checklogin.php? Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490127 Share on other sites More sharing options...
vasoftwaresolutions Posted March 12, 2008 Author Share Posted March 12, 2008 yes Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490128 Share on other sites More sharing options...
phpSensei Posted March 12, 2008 Share Posted March 12, 2008 Replace $sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); with $sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'"; $result=mysql_query($sql) or die(mysql_error()); // Mysql_num_row is counting table row $count=mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490129 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 Change: if($count==1){ To: if($count<0){ Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490130 Share on other sites More sharing options...
ohdang888 Posted March 12, 2008 Share Posted March 12, 2008 ohhhhhhhhh. i think i might see it... try this.. $sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'"; $result=mysql_query($sql) or die(mysql_error()); that will show you errors in your query, and that might be the root of the problem... Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490131 Share on other sites More sharing options...
phpSensei Posted March 12, 2008 Share Posted March 12, 2008 ohhhhhhhhh. i think i might see it... try this.. $sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'"; $result=mysql_query($sql) or die(mysql_error()); that will show you errors in your query, and that might be the root of the problem... Wow, thats just what I posted. @derick: your not solving the problem by doing that, infact that makes it worst. Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490132 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 lol I think you should change the IF statement part though. And if that doesn't work...try the mysql_error(); Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490133 Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2008 Share Posted March 12, 2008 mysql_numrows is an old depreciated function alias. Don't use it and don't suggest it as a solution, as it has nothing to do with the error. Your mysql_query is failing, but your code has no error checking to get it to tell you what the problem is. You might have a session problem as well, because session_register() is also an old and depreciated function and only works when register globals are on. To find your actual problem, change your mysql_query to the following - $result=mysql_query($sql) or die("The fricken query has no error checking: " . mysql_error()); Edit: Third times the charm (error checking should have been the first suggestion.) Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490134 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 mysql_numrows is an old depreciated function alias. Don't use it and don't suggest it as a solution, as it has nothing to do with the error. Sorry, I am old school. >.< lol Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490137 Share on other sites More sharing options...
ohdang888 Posted March 12, 2008 Share Posted March 12, 2008 ahahahah sorry phpsensi... i had just just said that on the last topic i was on and it was fresh in my mind.... didn't mean to offend any1.... and this topic is going so fast i hadn't look through all the posts..... but ya... Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490138 Share on other sites More sharing options...
vasoftwaresolutions Posted March 12, 2008 Author Share Posted March 12, 2008 ok it works now but i am getting this ... "Unknown column 'password' in 'where clause'" Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490140 Share on other sites More sharing options...
vasoftwaresolutions Posted March 12, 2008 Author Share Posted March 12, 2008 never mind about my last post.. but now its saying that i have this "Wrong Username or Password " Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490142 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 I don't know if this has anything to do with it but: $sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' AND password='$password'"; If changing the and to AND has nothing to do with it, please let me know. Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490143 Share on other sites More sharing options...
ohdang888 Posted March 12, 2008 Share Posted March 12, 2008 check your spelling of everything, the code AND the db... and if your table name is always "pilot" in this query, then just change it to `pilot` in the query.... less room for error... idk... it seems redundant to use a variable for something that is always the same... Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490144 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 I don't know why but: $result=mysql_query($sql); Shouldn't that be: $result=mysql_query("$sql"); ??? Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490148 Share on other sites More sharing options...
ohdang888 Posted March 12, 2008 Share Posted March 12, 2008 well when you are registering users, are you using MD5 to protect passwords?? cuse then you have to use MD5 in the password field in queries that search by passwords... Link to comment https://forums.phpfreaks.com/topic/95726-php-login/#findComment-490149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.