sqlfr28 Posted January 1, 2012 Share Posted January 1, 2012 I am getting the following error - Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in I:\wamp\www\1\session handling\signin.php on line 7 Here is the code- <?php extract($_POST); $cn=mysql_connect('localhost','root',''); mysql_select_db('db1',$cn); $sql="select user_type from user_dtl where login='$uname' and passwd='$pswd'"; $result=mysql_query($sql,$cn); $num=mysql_num_rows($result); if($num>0) { $utype=mysql_result($result,0,"user_type"); session_start(); $_SESSION['utype']=$utype; $_SESSION['uname']=$uname; if($utype=="A") { header('location:admin.php'); } else if($utype=="G") { header('location:home.php'); } } else { echo "Invalid username/password.<a href='signin.html'>Try again</a> } ?> I have created the database "db1" with a table caled 'user_dtl' with the following fields - 'uid','uname','pswd','user_type' . is it OK? Quote Link to comment https://forums.phpfreaks.com/topic/254152-php-session/ Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 The error means your query is invalid, if those are your field names, why have you specified different ones in your code? Quote Link to comment https://forums.phpfreaks.com/topic/254152-php-session/#findComment-1302998 Share on other sites More sharing options...
sqlfr28 Posted January 1, 2012 Author Share Posted January 1, 2012 Hi AK, can you pls rectify the code? I didnt get u properly. Please.. Quote Link to comment https://forums.phpfreaks.com/topic/254152-php-session/#findComment-1303023 Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 Hi AK, can you pls rectify the code? I didnt get u properly. Please.. won't write the code for you, but I will explain further what I am saying. you state that your field names for the table in use are 'uid','uname','pswd','user_type'. now in your query, $sql="select user_type from user_dtl where login='$uname' and passwd='$pswd'"; you are wanting to select data where the field login = $uname and the field passwd = $pswd. my question to you was where did the "login" and "passwd" fields come from that you have specified in your query? Quote Link to comment https://forums.phpfreaks.com/topic/254152-php-session/#findComment-1303070 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.