Good day,
I made a login.php, so the user can login into the page. After writing the script and checking the file to find some mistakes I made, the page login.php doesn't show anything. Even the source code displays only <body></body>
.
Here is the code to make a connection to the database.
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(E_ALL);
session_start();
$servername = "xx";
$username = "xx";
$password = "xx";
try {
$conn = new PDO ("mysql:host=$servername;dbname=xx", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo "Verbindung fehlgeschlagen: " . $e->getMessage();
}
Don't mind the "xx". And no, this is not in my real script. And now the script for the user to login to the page:
//fetch data
if(isset($_GET['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$statement = $conn->prepare("SELECT * FROM usertable WHERE username=:username");
$result = $statement->execute(array('username' => $username));
$user = $statement->fetch();
//Check password
if($user !== true && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
exit('Anmeldung war erfolgreich. Gehe zurück zu <a href="veranstaltungen.php">der Hauptseite</a>, aber das ist ein Geheimnis.');
} else {
$errorMessage = "E-Mail oder Passwort war FALSCH!!<br>";
}
}
And the form, which should be on the page so the user can type in his data to login.
<form action="?login=1" method="post">
<input class="uk-input uk-from-width-medium" type="text" name="username" placeholder="Benutzername eingeben">
<input class="uk-input uk-from-width-medium" type="password" name="password" placeholder="Passwort">
<input class="uk-button" type="submit" value="login">
</form>
What am I doing wrong here? Sublime Text doesn't also display errors or warnings. Thank you kindly.
Try change
if(isset($_GET['login'])) {
to
if(isset($_POST['username'])) {
I actually found out what I'm doing wrong here... The first line
ni_set("display_errors", 1);
was wrong the entire time. It should be "ini_set("display_errors", 1);". I sat so many hours infront of that script trying to figure out what's wrong here. I cursed for nothing. I just love my job. But still, thank you guys and sorry for the inconvience.
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.