我似乎无法从数据库中提取除用户名和 ID 之外的任何其他用户信息,而且我不明白为什么,这是我的代码试图从会话中调用它。
// Now we check if the data was submitted, isset will check if the data exists.
if ( !isset($_POST['username'], $_POST['password']) ) {
// Could not get the data that should have been sent.
die ('Username and/or password does not exist!');
}
// Prepare our SQL
if ($stmt = $con->prepare('SELECT id, password FROM accounts WHERE username = ?')) {
// Bind parameters (s = string, i = int, b = blob, etc), hash the password using the PHP password_hash function.
$stmt->bind_param('s', $_POST['username']);
$stmt->execute();
$stmt->store_result();
// Store the result so we can check if the account exists in the database.
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $password);
$stmt->fetch();
// Account exists, now we verify the password.
if (password_verify($_POST['password'], $password)) {
// Verification success! User has loggedin!
$_SESSION['loggedin'] = TRUE;
$_SESSION['username'] = $_POST['username'];
$_SESSION['id'] = $id;
$_SESSION['title'] = $title;
$_SESSION['website'] = $website;
$_SESSION['youtube'] = $youtube;
$_SESSION['facebook'] = $facebook;
$_SESSION['paypalemail'] = $paypalemail;
echo 'Welcome ' . $_SESSION['username'] . '!';
echo 'Welcome ' . $_SESSION['title'] . '!';
echo'<a href="/profile.php">My Profile </a>';
} else {
echo 'Incorrect username and/or password!';
}
} else {
echo 'Incorrect username and/or password!';
}
$stmt->close();
} else {
echo 'Could not prepare statement!';
}
?>
答案1
变量$title
、$website
、$youtube
、从哪里来的?如果它们存储在表中,并且列名与您使用的变量名相同$facebook
,则需要将它们与 ID 和密码一起检索。$paypalemail
accounts
改变
if ($stmt = $con->prepare('SELECT id, password FROM accounts WHERE username = ?')) {
到
if ($stmt = $con->prepare('SELECT
`id`,
`password`,
`title`,
`website`,
`youtube`,
`facebook`,
`paypalemail`
FROM accounts WHERE username = ?')) {