I'm working on a login script, but it doesn't let me sign in even though the account information are correct. I've used this login script in the past, but it used MySQL, so I changed a couple of things so I would work with MySQLi, but it doesn't.
Config.php
<?php
$con = mysqli_connect("localhost","root","wachtwoord","huizenverkoop");
// Database verbinding controleren
if (mysqli_connect_errno()){
echo "Kan geen verbinding maken met MySQL: " . mysqli_connect_error();
}
?>
Updated: login.php
include 'config.php';
if(isset($_SESSION['persoon'])!="")
{
header("Location: index.php");
}
if(isset($_POST['loginnu']))
{
$gebruikersnaam = mysqli_real_escape_string($con, $_POST['gebruikersnaam']);
$wachtwoord = mysqli_real_escape_string($con, $_POST['wachtwoord']);
$gebruikersnaam = trim($gebruikersnaam);
$wachtwoord = trim($wachtwoord);
$query = "SELECT id, gebruikersnaam, wachtwoord FROM persoon WHERE gebruikersnaam='$gebruikersnaam'";
$row = mysqli_query($con,$query);
$count = mysqli_num_rows($row);
if($count == 1 && $row['wachtwoord']==md5($wachtwoord)){
$_SESSION['persoon'] = $row['id'];
header("Location: index.php");
}else{
header("Location: login.php?fout=true");
}
}
if (@$_GET['fout'] == 'true'){
$melding = "De ingevulde gegevens kloppen niet.";
include('alert.php');
}
Gebruikersnaam means username and wachtwoord means password. When I press the button "log in" it sends me to login.php?fout=true. Fout means wrong.
<form method="post">
<h1 class="box-titel">Inloggen</h1>
<div class="controle">
<input type="text" class="speciaal-tekstveld" name="gebruikersnaam" placeholder="Gebruikersnaam" required>
<input type="password" class="speciaal-tekstveld" name="wachtwoord" placeholder="Wachtwoord" required>
</div>
<input type="submit" class="grootknop" name="loginnu" value="Inloggen">
</form>
Persoon table:
id int(2)
gebruikersnaam varchar(50)
wachtwoord varchar(255)
Could someone please help me?