r/PHPhelp • u/HKON_ • May 19 '20
Login php not working, giving me error code wrongpswd1 althoug my pwd and user is correct thank you in advance for your help and time
<?php
if(isset($_POST['login-submit'])){
require 'config.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid)|| empty($password)){
header("Location:../index.php?error=emptyfields");
exit();
}
else {
$sql = "SELECT * FROM user_account WHERE uidusers = ? OR emailusers = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location:../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if($row = mysqli_fetch_assoc($result)){
$pwsdcheck = password_verify($password, $row['pwdusers']);
if($pwsdcheck == false){
header("Location:../index.php?error=wrongpwsd1");
exit();
}
else if ($pwsdcheck == true) {
session_start();
$_SESSION['userid'] = $row['id'];
$_SESSION['useruid'] = $row['uidusers'];
header("Location:../main.php?login=success");
exit();
}
else {
header("Location:../index.php?error=wrongpwsd");
exit();
}
}
else {
header("Location:../index.php?error=nonexistinguser");
exit();
}
}
}
}
else {
header("Location:../index.php");
exit();
}
10
Upvotes
1
u/lovesrayray2018 May 19 '20
I dont see code thats initializing $conn, but ur using it
$stmt = mysqli_stmt_init($conn);
1
2
u/bla4free May 19 '20
Verify the password form name is
pwd. Doecho $_POST['pwd'];and verify PHP is getting the entered password.Use
password_hash()and re-encrypt the password for that user then try logging in again.