Jump to content

PHP Session


sqlfr28

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/254152-php-session/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/254152-php-session/#findComment-1303070
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.