当用户登录到该成员的唯一区域时,我正在尝试提取其他数据,例如他们的名字以及他们的登录凭据,即电子邮件和密码,但似乎无法使查询成功输出数据。它成功登录但我无法将任何其他内容传递到Session
<?php
session_start();
@$db = new mysqli("localhost", username, password, table);
if ($db->connect_errno !=0) {
exit;
}
$usern = $_POST['username'];
$passw = $_POST['passw'];
$query = "SELECT * FROM cf_users WHERE(firstname='".$firstName."' and email='".$usern."' and password='".$passw."')";
$db->query($query);
$result = $db->query($query);
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
if($row[0]>0) {
$_SESSION['email'] = $usern;
$_SESSION['firstName'] = $row['firstName']; // Modified after suggestion
header("location: page.php");
exit();
}
else {
exit("Login Failed.<br/>'.
'Please fill them in and try again. <a href='javascript:history.go(-1)'>Go back</a>");
}
$closed = $db->close();
?>
答案 0 :(得分:0)
您也应该将session_start();
添加到page.php
的开头。
并注意该行
$_SESSION['firstName'] = $firstName;
因为$firstName
未定义。