1

I was following a tutorial to create a loginsystem in php. This is my login script right after you fill in your email and password to login.

<?php

if (isset($_POST['login-submit'])) {
    //link maken met database
    require 'dbh.inc.php';
    $email = $_POST['mailuid'];
    $pwd = $_POST['password'];

    //zijn alle velden ingevuld?
    if (empty($email) || empty($pwd)) {
        header("location: ../index.php?error=emptyfields&email=".$email);
        exit();
    }
    else{
        $sql = "SELECT * FROM users WHERE emailUsers=?";
        $stmt = mysqli_stmt_init($conn);

        //check of de sql stmt valid is.
        if (!mysqli_stmt_prepare($stmt, $sql)) {
            header("location: ../index.php?error=sqlerror");
            exit();
        }
        else{
            mysqli_stmt_bind_param($stmt, "s",  $email);
            mysqli_stmt_execute($stmt);
            $result = mysqli_stmt_get_result($stmt);
            if ($row = mysqli_fetch_assoc($result)) {
                $pwdCheck = password_verify($pwd, $row['pwdUsers']);
                if ($pwdCheck == false) {
                    header("location: ../index.php?error=wrongpwd");
                    exit();
                }
                elseif($pwdCheck == true){
                    session_start();
                    $_SESSION['userId'] = $row['idUsers'];
                    $_SESSION['userEmail'] = $row['emailUsers'];

                    header("location: ../index.php?login=success");
                    exit();
                }
                else{
                    header("location: ../index.php?error=wrongpwd");
                    exit();
                }
            }
            else{
                header("location: ../index.php?error=nouser");
                exit();
            }
        }
    }
}
else{
    header("location: ../index.php");
    exit();
}

The code is working fine on my localhost. But on my website server it just isn't working. Whe this code runs the code just stops. You don't get send to a next page.

I think it get's stuck somewhere around this part:

$result = mysqli_stmt_get_result($stmt);

The weird thing is that my register code is working fine. So I can create a new user and the information get's send to the database just fine. But the login script is not working at all. But these two scripts are really similar.

Thank you for all the help!

Timo Vossen
  • 303
  • 2
  • 3
  • 10
  • Check the options enabled as per https://stackoverflow.com/questions/45001819/php-fatal-error-call-to-undefined-function-mysqli-stmt-get-result – Nigel Ren Jun 13 '20 at 14:44
  • 1
    First, you have to configure the error reporting. Then get the error. Then google for the solution – Your Common Sense Jun 13 '20 at 14:58

0 Answers0