1

I am having a little trouble with a login script. You can probably tell im pretty new to this. I have troubleshooted the problem to being in the if(password_verify) statement! All help is appreciated, and please critique anything if noticed!

<?php

ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$email = $_POST["email"];
$password = $_POST["password"];
require '../../usersTable.php';
$stmt_check = $conn->prepare("SELECT * FROM users WHERE email=?");
$stmt_check->bind_param("s", $email);
$stmt_check->execute();
if ($stmt_check->num_rows > 0) {
    if (password_verify($password, $row['password'])) {
        $conn->close();
        // Success!
        header('Location: ../')
    } else {
        $conn->close();
        // Invalid credentials
        echo 'Password Mismatch';
    }
} else {
    $conn->close();
    echo "incorrect Email!";
}
4
  • 2
    Check that your $row['password'] isn't a copy+paste error; it looks like you don't declare $row anywhere. Commented Jul 24, 2019 at 20:44
  • You are missing ; after header('Location: ../'). This will give you a syntax error. Commented Jul 24, 2019 at 20:59
  • Always exit() after header('Location: ...'); Commented Jul 24, 2019 at 21:00
  • WARNING: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong. Please, do not write your own authentication system when any modern development framework like Laravel comes with a robust authentication system built-in. Commented Jul 25, 2019 at 1:12

1 Answer 1

1

You have forgotten to add one line before your if(password_verify... line

$row = $stmt_check->get_result()->fetch_array();
if (password_verify($password, $row['password'])) {
    // ...

This will get a single row from your DB result.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.