0

I am programming a login system. When i click on submit, it stays in the userController and doesn't echo anything. i'm fairly new when it comes to programming so can anyone help me with this issue?

This is what it looks line in the template:

<div class="container">
    <div class="top">
        <h1 id="title" class="hidden"><span id="logo"> <img src="assets/img/logo.jpg" alt="Commercium logo"></span>
    </div>
    <div class="login-box animated fadeInUp">
        <div class="box-header">
            <h2>Log In</h2>
        </div>
        <form method="post" action="../controller/userController.php">
            <input name="action" type="hidden" value="loginUser" required/>
        <label for="email">E-mail adres</label>
        <br/>
        <input type="email" name="email" placeholder="enter email">
        <br/>
        <label for="wachtworrd">Wachtwoord</label>
        <br/>
        <input type="password" name="password" placeholder="Password">
        <br/>
        <button type="submit" value="Login" name="login">Sign In</button>
        <br/>
        <a href="index.php"><p class="small">
        </p></a>
    </div>
</div>

This is what it looks like in the controller

if (isset($_POST['login'])) {
    $login = $user->loginUser($_POST['email'], $_POST['password']);
}

and this is the class

public function loginUser($email, $password)
{
    $stmt = $this->connect()->prepare("SELECT * FROM users WHERE email= ? AND password= ? ");
    $stmt->bind_param('ss', $email, $password);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->num_rows;

    if ($num_rows == 1) {
        echo 'U bent ingelogd!';
    }
    if ($num_rows == 0)
    {
        echo "geen gegevens";
    }
}
tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

$num_rows is not defined in the loginUser() function. It should be

if ($row == 1) {
    echo 'U bent ingelogd!';
}
if ($row == 0){    
    echo "geen gegevens";   
}

Also you shouldn't be storing passwords in plain-text. Use php's password_hash() to hash the password and password_verify() to verify that the password from the html form matches the stored hash

Have a look at this question regarding password_hash()

Also checkout the manual for password_hash

and

for password_verify

Rotimi
  • 4,783
  • 4
  • 18
  • 27