For more context, I’m following this youtube tutorial How To Create A Login System In PHP For Beginners | Procedural MySQLi | PHP Tutorial by Dani Krossing
Hi! I’m building a PHP website where a user/admin can sign-up and log-in, the sign-up form works fine, but once I type the username and the password into the login form and enter, it doesn’t read or find the password, it will echo “Incorrect password”.
The URL redirects to http://localhost:8080/EARIST/login.php?error=wronglogin
.
This is the function that runs when the user has filled all the blanks:
function loginUser($conn, $username, $password) {
$idExists = idExists($conn, $username, $username);
if ($idExists === false) {
header("location: ../EARIST/login.php?error=nousernameexists");
exit();
}
$pwdHashed = $idExists["password"];
$checkPwd = password_verify($password, $pwdHashed);
if ($checkPwd === false){
header("location: ../EARIST/login.php?error=wronglogin");
exit();
} else if ($checkPwd === true) {
session_start();
$_SESSION["id"] = $idExists["id"];
$_SESSION["username"] = $idExists["username"];
header("location: ../EARIST/EARIST.php");
exit();
}
}
This is the function that checks the data inside the database:
function idExists($conn, $email, $username) {
$sql = "SELECT * FROM login WHERE email = ? OR username = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../EARIST/signin.php?error=stmtfailed");
exit();
}
mysqli_stmt_bind_param($stmt, "ss", $email, $username);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result($stmt);
if($row = mysqli_fetch_assoc($resultData)) {
return $row;
} else {
$result = false;
return $result;
}
mysqli_stmt_close($stmt);
}
I know my explanation is very messy and I’m very sorry about that. I hope you can help me to figure it out. I’m new to this forum so I don’t know how to ask properly, I’m sorry and thank you.