bleured27 Posted June 14, 2012 Share Posted June 14, 2012 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in G:\xampp\htdocs\checklogin.php on line 27 verkeerde naam of wachtwoord hy help needed i serched on the internet for a solution "i cant find a good 1 zo plz help me" <?php ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="brsgamev1.0"; // Database name $tbl_name="thegamev1.0"; // Table name // Connect to server and select databse. mysql_connect("$host", "$user", "$pass")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $user=$_POST['user']; $pass=$_POST['pass']; $user = stripslashes($user); $pass = stripslashes($pass); $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $sql="SELECT * FROM $tbl_name WHERE user='$user' and pass='$pass'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("user"); session_register("pass"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 You need to check if $result is not false before attempting to use it. $result being false means your query failed or returned no rows. Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1353867 Share on other sites More sharing options...
mrMarcus Posted June 14, 2012 Share Posted June 14, 2012 Not relevant, but, replace session_register with $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1353869 Share on other sites More sharing options...
bleured27 Posted June 14, 2012 Author Share Posted June 14, 2012 hy tnx for the quik mssg i dont need the relevant stuf still tnx <not whole script> still i need to know how to replase the $quer or it cant becose there are 3 fields in table and only 1 accaunt? Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1353873 Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 For pete's sake if you want help at least show us you care enough about what you're doing to sit down and write a proper sentence explaining what is wrong and what you want, and demonstrate that you've tried the suggestions already. Spelling matters. Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1353877 Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 $result being false means your query failed or returned no rows. $result will still be a valid resource if the query returns 0 rows. hy tnx for the quik mssg i dont need the relevant stuf still tnx <not whole script> still i need to know how to replase the $quer or it cant becose there are 3 fields in table and only 1 accaunt? Huh? What does the following yield? $result=mysql_query($sql) or die('Query: ' . $sql . '<br />Error: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1353878 Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 $result being false means your query failed or returned no rows. $result will still be a valid resource if the query returns 0 rows. I thought it was, but I had a brain fart. Ty. Quote Link to comment https://forums.phpfreaks.com/topic/264190-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1353887 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.