
</script>
<script type="text/javascript">
    $(document).ready( function() {
            $.getJSON('https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/read.php',
                function(json){

                    // cf. https://api.jquery.com/jQuery.getJSON/
                    $.each( json, function( key, val ) {
                        var login = val[1],
                        var password = val[2]
                    });
                }
            )
        });
</script>

<?php
// on se connecte à la bdd
require_once('template_header.php');

$login = "anonymous";
$errorText = "";
$successfullyLogged = false;

if(isset($_POST['login']) && isset($_POST['password'])){
    $tryLogin=$_POST['login'];
    $tryPwd=$_POST['password'];

    //si login existe 
    if($result->num_rows != 0) {
        $identite=$result->fetch_assoc();
        //si le mdp est correct
        if($identite['PASSWORD']==$tryPwd){
            $successfullyLogged = true;
            $login = $tryLogin;
            $password = $tryPwd;
        } else
        $errorText = "Erreur de login/password1";

    } else
        $errorText = "Erreur de login/password2";

} else
    $errorText = "Merci d'utiliser le formulaire de login";
        
if(!$successfullyLogged) {
    echo $errorText;
} else {
        session_start();
        $_SESSION['login']=$login;
        $_SESSION['password']=$password;
        header('Location: home.php');


}

?>
