Guten Tag,
Ich habe einen Fehler beim einloggen in mein Loginsystem mit PHP. Ich kann user registrieren, also der username und der password_hash werden richtig in der DB gespeichert. Wenn ich mich aber mit einem bestehenden user der in der Datenbank existiert anmelden möchte, klappt das nicht und es kommt diese Fehlermeldung:
Fehlermeldung Beginn:
Warning: Trying to access array offset on value of type bool in C:\xampp\htdocs\login.php on line 16
Anmeldung fehlgeschlagen, versuche es erneut.
Fehlermeldung Ende.
Mein PHP register Script:
<?php
// Datenbankverbindung
include ('connection.php');
// Benutzereingabe aus Formular
$username = $_POST['username'];
$password = $_POST['password'];
// Das Passwort hashen
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
// SQL-Abfrage, um den Benutzer in der Datenbank zu speichern
$sql = "INSERT INTO users (username, password_hash) VALUES (?, ?)";
$stmt = $conn->prepare($sql);
$stmt->execute([$username, $hashedPassword]);
// Erfolgsmeldung oder Weiterleitung zur Anmeldeseite
header('Location: login.html');
?>
Mein PHP login Script:
<?php
// Datenbankverbindung
include ('connection.php');
// Benutzereingabe aus Formular
$username = $_POST['username'];
$password = $_POST['password'];
// SQL-Abfrage, um das gespeicherte Passwort abzurufen
$sql = "SELECT password_hash FROM users WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->execute([$username]);
$row = $stmt->fetch();
// Überprüfen, ob das eingegebene Passwort korrekt ist
if ($row && password_verify($password, $row['password_hash'])) {
// Anmeldung erfolgreich, führe die notwendigen Aktionen aus
// z.B., setze eine Sitzung und leite den Benutzer weiter
session_start();
header('Location: index.html');
} else {
echo "Anmeldung fehlgeschlagen, versuche es erneut.";
}
?>
Wäre cool wenn mir jemand bei diesem Problem weiterhelfen könnte, bin noch nicht so fit in dieser Thematik.
Also wenn ich das nutze kommt ein error "not all parameters were used in the sql statement" Hast du vllt ne lösung?