shortysbest Posted April 7, 2010 Share Posted April 7, 2010 I am making a user login and registration page and i have it setup and it works 100% perfect on my localhost, but now i am trying to set it up on my webserver but i get that error message. it says this line of code is not a valid MySQL result resource $numrows = mysql_num_rows($query); This is my whole login.php code <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost","*******","******") or die ("couldn't connect!"); mysql_select_db("k297merchanting_zzl_members") or die("couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check to see if they match if ($username==$dbusername&&md5($password)==$dbpassword) { header ("location:../sw.php?page=item"); echo "Login Successful. You are being redirected to the members page."; $_SESSION['username']=$dbusername; } else echo "Incorrect Password!"; } else die("That user doesn't exist!"); } else die("please enter a username and a password"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/197942-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/ Share on other sites More sharing options...
oni-kun Posted April 7, 2010 Share Posted April 7, 2010 Try changing the query line to this: $query = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error()); You are not checking if the query works or not, Therefor mysql_num_rows fails as there's obviously a problem. Quote Link to comment https://forums.phpfreaks.com/topic/197942-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1038678 Share on other sites More sharing options...
shortysbest Posted April 8, 2010 Author Share Posted April 8, 2010 Try changing the query line to this: $query = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error()); You are not checking if the query works or not, Therefor mysql_num_rows fails as there's obviously a problem. Thanks, that got rid of the errors. but im still having troubles connecting to my database on my server.. :| Quote Link to comment https://forums.phpfreaks.com/topic/197942-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1038682 Share on other sites More sharing options...
oni-kun Posted April 8, 2010 Share Posted April 8, 2010 "localhost" Most of the shared host *SQL server hosts I've worke with were not "localhost", Why not look in the FAQ's or ask your hosting support? Quote Link to comment https://forums.phpfreaks.com/topic/197942-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1038698 Share on other sites More sharing options...
shortysbest Posted April 8, 2010 Author Share Posted April 8, 2010 "localhost" Most of the shared host *SQL server hosts I've worke with were not "localhost", Why not look in the FAQ's or ask your hosting support? mine is. it says it in the details box. MySQL Hostname * localhost but do you know any good php hosting sites w/ easy to use mysql hosting and all. preferably free to use. i havent had much look finding any good php hosts. Quote Link to comment https://forums.phpfreaks.com/topic/197942-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1038707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.