So here is my form I use to get the email and password, don't mind all the tabs xD.
<form method="post" action="">
<ul>
<label for='usermail'>email </label>
<input type='text' name='email' placeholder="jouwnaam@mail.nl" required>
</ul>
<ul>
<label for="password">Wachtwoord</label>
<input type="password" name="wachtwoord" placeholder="wachtwoord" required>
</ul>
<ul>
<div class='login-btn btn btn-default btn-lg'><input name="submit" type="submit" value="Inloggen"></div>
</ul>
</form>
And this is my PHP code:
<?php
if (isset($_POST['inloggen']))
{
mysql_connect("localhost","root","usbw") or die('error');
mysql_select_db("sportschool") or die('error');
$k_email = $_POST['email'];
$wachtwoord = $_POST['wachtwoord'];
echo $k_email;
if (mysql_query("SELECT * FROM klant;") == false)
{
echo mysql_error();
}
else
{
$resultaat = mysql_query("SELECT wachtwoord FROM klanten WHERE email='".$k_code."';");
$data = mysql_fetch_assoc($resultaat);
echo "<br />";
echo "<br />";
$k_wachtwoord = $data["wachtwoord"];
echo $k_wachtwoord;
if ($wachtwoord==$k_wachtwoord)
{
echo "U are logged in";
session_start();
$_SESSION['ingelogd'] = true;
$_SESSION['klantemail'] = $k_email;
}
else
{
echo "Username or Password is not right try again.";
}
echo "<br />";
mysql_close();
}
}
?>
Every time I login with the correct email and password the page is refreshed but I don't get the echo for logged in or the error for not logging in.
I have this PHP code which checks if the user is logged in, and that one stays on not logged in:
<?php
if ((isset($_SESSION['ingelogd'])) && ($_SESSION['ingelogd'] == true))
{
echo $_SESSION['klantemail']." is ingelogd";
}
else
{
echo "Nog niet ingelogd.";
}
?>
I don't use PHP a lot, so there may be a lot of mistakes.