实际上是在构建登录和注册系统,但是如果用户的email和email_code匹配,当试图将active
表更改为1时,电子邮件激活部分会出现这些内部错误。
activate.php代码:
<?php
} else if (isset($_GET['email'], $_GET['activation']) === true) {
$email = trim($_GET['email']);
$email_code = trim($_GET['activation']);
if (email_exists($email) == false) {
$errors[] = 'Ooops, We counldn\'t find that email address';
} else if (activate($email, $email_code) == false) {
$errors[] = 'Ooops, We had problem activating your account';
}
if (empty($errors) == false){
echo output_errors($errors) . '<br><br>';
} else {
header('Location : activate.php?success');
exit();
}
} else {
header('Location: index.php');
exit();
}
?>
activate($ email,$ email_code)函数:
function activate($email, $email_code) {
global $connection;
$email = $email;
$email_code = $email_code;
$active = 0;
$new_update_active = 1;
$stmt = $connection -> prepare('SELECT id FROM users WHERE email = ? AND email_code = ? AND active = ?');
$stmt -> bind_param('ssi', $email, $email_code, $active);
$stmt -> execute();
$stmt -> store_result();
$stmt -> fetch();
if ($stmt -> num_rows() == 1) {
$update_active = $connection -> prepare('UPDATE users SET active = ? WHERE email = ?');
$update_active -> bind_param('is', $new_update_active, $email);
return true;
} else {
return false;
}
}
该代码似乎是正确的,并且仅在涉及email
和email_code
匹配的部分并将数据库中的active
表更改为1时才具有这些内部服务。
答案 0 :(得分:1)
后来我发现了错误,我只是改变了
header('Location : activate.php?success');
到
header('Location: activate.php?success');