过去几个月我在PC上本地创建了一个网站。 我现在已经购买了一个域并上传了我的文件和数据库。
由于某种原因,我无法想到,用户无法再登录该网站 - 我还检查了我的登录凭证与UK2.net他们说他们都是正确的。
可能出现什么问题?
登录表单
<form action="login.php" method="post" >
Email<br />
<input name="email" type="text" /><br /><br />
Password<br />
<input name="password" type="password" /><br />
<input name="submit" type="submit" value="Log In" />
</form>
登录PHP:
require_once('/scripts/includePDO.php');
$error = '';
$form = $_POST['submit'];
$email = $_POST['email'];
$password = $_POST['password'];
if( isset($form) ) {
if( isset($email) && isset($password) && $email !== '' && $password !== '' ) {
$sql = "SELECT * FROM tbl_users WHERE email = :email and password = :password";
$q = $conn->prepare($sql); // the default way of PDO to manage errors is quite the same as `or die()` so no need for that
$q->bindValue(':email',$email,PDO::PARAM_STR);
$q->bindValue(':password',$password,PDO::PARAM_STR);
$q->execute();
$r = $q->fetch(PDO::FETCH_ASSOC);
if(($r)!=0)
{ //success
$answer = $r['id'];
$_SESSION['logged-in'] = true;
$_SESSION['who'] = $answer;
//If the login details are entered and they match those in the database, forward to new page.
header('Location: /home/');
exit;
// If information is wrong or missing, provide error message.
} else { echo "Sorry, something hasn't worked. Are you entering all the information correctly?"; }
}
}
答案 0 :(得分:0)
答案是 -
在脚本/ includePDO.php之前有一个斜杠,它不需要在那里,这使得无法找到该文件。