這是我正在處理的登錄腳本;它使用mysqli(我知道它不如PDO安全) 運行MySQL查詢後,我是fetch_object()。然後,我正在分配$ _session來保存用戶ID和電子郵件。 $ _SESSION ['uid'] = $ user-> ID有效,但不是$ _SESSION ['uemail'] = $ user-> email。這可能是因爲電子郵件存儲在$ user對象中嗎?我必須以某種方式轉換它嗎?
電子郵件是存儲屁股varchar(255)在數據庫ID是int(11)。
<?php
include_once("config.php");
$username = $_POST['username'];
$password = sha1($_POST['password']);
$query = "SELECT ID FROM user WHERE username = '$username' AND password = '$password' LIMIT 1";
if ($result = $db->query($query)) {
while ($user = $result->fetch_object()) {
$_SESSION['uid'] = $user->ID;
$_SESSION['uemail'] = $user->email ;
header("Location: index.php");
//exit();
}
}else {
echo "Invalid login information. Please return to the previous page.";
//exit();
}
//var_dump(get_object_vars($result));
//$db->close();
?>
在此先感謝。
''SELECT ID,email FROM ...' - 因爲您還需要選擇'email'列 – 2014-10-19 00:36:04
謝謝,我只是想將其改爲* – woodchuck 2014-10-19 00:39:59
不客氣 – 2014-10-19 00:40:28