I have spent the last few months creating a website locally on my PC. I have now purchased a domain and uploaded my files, and database.
For some reason I cannot think of, users can no longer login to the website - and I have also check my login credentials with UK2.net and they said they are all correct.
What might be going wrong?
Login Form:
<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>
Login 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?"; }
}
}
The answer was -
There was a slash before scripts/includePDO.php that did not need to be there, which made it impossible to find the file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.