$query = "SELECT * FROM users WHERE username = '$username'";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) < 1)
{
header("Location: ../index.php?login=username");
exit();
}
else
{
if($row = mysqli_fetch_assoc($query_run))
{
//deshashing password
$hashedPwdCheck = password_verify($password, $row['password']);
if($hashedPwdCheck == false)
{
header("Location: ../index.php?login=false");
exit();
}
elseif($hashedPwdCheck == true)
{
//login the user here
$_SESSION ['u_name'] = $row['username'];
$_SESSION ['u_email'] = $row['email'];
$_SESSION ['u_password'] = $row['password'];
$_SESSION ['u_id'] = $row['userid'];
header("Location: ../index.php?login=success");
exit();
above is the login code.
Below is the register code that stores the password and hashes it.
else
{
//hashing password
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
//insert the user into the database
$query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$hashedPwd');";
mysqli_query($con, $query);
header("Location: ../register.php?register=success");
exit();
}
Please help, I'm a little confused as to why this isn't working.
Regards, Ross