I have a form in this index.html page with an Ajax script, on clicking the submit button it should just display "Authentification succeeded" or not, if the user is in the database, it works but when I hit submit it displays the message for only one second. How can I keep the message displayed? Here's the index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accueil</title>
<style type="text/css" media="screen">
h1 {
color:red;
}
</style>
<script language="javascript">
function chargement()
{
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var x = new XMLHttpRequest();
x.open('GET','verif.php?email='+email+'&password='+password,true);
x.onreadystatechange = function()
{
if ((x.readyState == 4 ) && (x.status == 200))
{
document.getElementById('res').innerHTML= x.responseText;
}
}
x.send();
}
</script>
</head>
<body>
<h1>Bienvenu(e) à Affariyet.tn </h1>
<table>
<form action="index.html" method="GET">
<tr>
<td>Email :</td>
<td> <input type="text" id ="email" name="email" value="" placeholder="Votre Email"><br></td>
</tr>
<tr>
<td>Mot De Passe : </td>
<td><input type="password" id="password" name="password" value="" placeholder="Votre Mot De Passe"><br></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="auth" value="S'authentifier" onclick="chargement()">
<input type="reset" name="reset" value="Annuler">
</td>
</tr>
<tr>
<td></td>
<td><div id="res"> </div></td>
</tr>
</form>
</table>
</body>
</html>
And this is the PHP file that has the verification function :
<?php
include 'config.php';
class main
{
public $conn;
function __construct()
{
$c=new config();
$this->conn=$c->connexion();
}
function verif($conn,$email,$password)
{
$req="SELECT `Email`,`Password` FROM utilisateur WHERE `Email`='$email' AND `Password`='$password' ";
$res=$conn->query($req);
return $res->RowCount();
}
}
$m=new main();
$email=$_GET['email'];
$password=$_GET['password'];
$resultat=$m->verif($m->conn,$email,$password);
if($resultat==0)
{
echo '<h4 style="color:red;"> Email ou mot de passe erroné</h4>';
}
else
{
echo '<h4 style="color:green;">Authentification réussie. Accéder à la <a href=produit.php>Liste des produits</a></h4>';
}
?>