我编写了以下代码并得到了一个未经检验的文件结束错误。你明白为什么吗? 错误是指我的最后一行代码。 我在stackoverflow和其他论坛上阅读了有关此错误的其他页面,按照他们的说明进行操作但仍然无效。
<?php
session_start();
$pdo = new PDO(...);
if(isset($_GET['register'])) {
$error = false;
$email = $_POST['email'];
$passwort = $_POST['passwort'];
$passwort2 = $_POST['passwort2'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'Bitte eine gültige E-Mail-Adresse eingeben<br />';
$error = true;
}
if(strlen($passwort) == 0) {
echo 'Bitte ein Passwort angeben<br />';
$error = true;
}
if(strlen($firstName) == 0) {
echo 'Bitte ein Passwort angeben<br />';
$error = true;
}
if(strlen($lastName) == 0) {
echo 'Bitte ein Passwort angeben<br />';
$error = true;
}
if($passwort != $passwort2) {
echo 'Die Passwörter müssen übereinstimmen<br />';
$error = true;
}
if(strlen($username) == 0) {
echo 'Please enter a username<br />';
$error = true;
//Überprüfe, dass die E-Mail-Adresse noch nicht registriert wurde
if(!$error) {
$statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$result = $statement->execute(array(':email' => $email));
$mail = $statement->fetch();
if($mail !== false) {
echo 'Diese E-Mail-Adresse ist bereits vergeben<br />';
$error = true;
}
}
if(!$error) {
$statement = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$result = $statement->execute(array(':username' => $username));
$user = $statement->fetch();
if($user !== false) {
echo 'Diese E-Mail-Adresse ist bereits vergeben<br />';
$error = true;
}
}
//Keine Fehler, wir können den Nutzer registrieren
if(!$error) {
$passwort_hash = password_hash($passwort, PASSWORD_DEFAULT);
$statement = $pdo->prepare("INSERT INTO users (email, passwort) VALUES (:email, :passwort)");
$result = $statement->execute(array('email' => $email, 'passwort' => $passwort_hash));
if($result) {
$link = '<a href="$_SESSION["lastPage"]">Login</a>';
$_SESSION["loggedIn"] = true;
die("The registration was successful.<br />$link");
} else {
echo 'There was a mistake. Please try again!<br />';
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sign in</title>
</head>
<body>
<form action="?register=1" method="post">
Firstname:<br />
<input type="text" size="40" maxlength="250" name="firstName"><br />
Lastname:<br />
<input type="text" size="40" maxlength="250" name="lastName"><br /><br />
username(used to login):<br />
<input type="text" size="40" maxlength="250" name="username"><br /><br />
E-Mail:<br />
<input type="email" size="40" maxlength="250" name="email"><br /><br />
Dein Passwort:<br />
<input type="password" size="40" maxlength="250" name="passwort"><br />
Passwort wiederholen:<br />
<input type="password" size="40" maxlength="250" name="passwort2"><br /><br />
<input type="submit" value="Sign In">
</form>
</body>
</html>