我使用this website实现了一个基本且简单的登录方法。我可以成功登录,但我想检索登录网站的成员的名字,以将其存储到$_SESSION
对象中。
$sql="SELECT * FROM users WHERE email='$myemail' and password='$mypassword'";
$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){
//$_SESSION[];
// header("Location:http://localhost/website/test.php");
}
else
echo "Wrong Username or Password";
答案 0 :(得分:1)
email
字段必须包含唯一条目。
请参阅id-4
& id-4
行包含完全相同的数据。
但至于你的答案,
if($count==1)
{
$row = mysql_fetch_assoc($result);
$f_name = $row['firstname'];
}
现在,如果email=cf@hotmail.com
和password=g
您的查询将失败,因为$count
将不会是1
。因此,有效用户也会看到登录失败消息。
答案 1 :(得分:1)
这是你想要做的吗?
if($count==1)
{
$row = mysql_fetch_row($result);
session_start();
$_SESSION['first_name'] = $row['firstname'];
header("Location:http://localhost/website/test.php");
}