I have been trying to get my login script to work but I haven't found a way to do it, it does actually log in but it doesn't check the database if the user has been registered or not, could any of you help me out? THis is the script I have been trying to get to work but haven't been able to yet.
Excuse me for the dutch words in the code.
Oh and don't worry about the md5, I'm just practicing not actually putting this site online :)
<?php
if (isset($_POST['username'])){
// backslashes verwijderen
$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['password']);
$username = mysqli_real_escape_string($conn, $username);
$password = mysqli_real_escape_string($conn, $password);
$password = md5($password);
$query = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$result = mysqli_query($conn,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
$data = mysqli_fetch_assoc($result);
if($rows==1){
// sessie aanmaken met de gebruikersnaam en doorsturen naar homepage
$_SESSION['username'] = $username;
$_SESSION['user_id'] = $data['id'];
header("Location: /");
}else{
echo "
<div class='form'>
<h3>Gebruikersnaam en/of wachtwoord is incorrect</h3>
<br/>Klik <a href='inloggen.php'>hier</a> om opnieuw te
proberen.
</div>
";
}
} else {
?>
<div class="form">
<h1>Log In</h1>
<form action="bloemen.html" method="post" name="login">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input name="submit" type="submit" value="Login" />
</form>
<p>Nog niet geregistreerd? <a href='registreren.php'>Registeren</a></p>
<p>Bent u een medewerker? <a href='medewerker-login.php'> Inloggen</a></p>
</div>