connexion forms

connexion forms

Hi all,


beginner, I try to create a login form.


I installed a JQuery plugin with a sliding panel hung on the top edge with the forms:
http://web-kreation.com/demos/Sliding_login_panel_jquery/# "> web-kreation.com


The best result I could get so far is the display of query results in the panel above the form, but I can not seem to find the error that prevents the script to interpret the response (1 or 0) It always display the error text input:

Form:

<div class="left">
      <div class="errorlog"></div>
      <div class="reponselog"></div>
        <!-- Login Form -->
        <form class="clearfix" id="formLogin">
          <h1>Member Login</h1>
          <label class="grey" for="login">Username:</label>
          <input class="field" type="text" name="login" id="login" value="" size="23" required />
          <label class="grey" for="mdp">Password:</label>
          <input class="field" type="password" name="mdp" id="mdp" size="23" required />
          <label>
          <input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" />
            &nbsp;Remember me</label>
          <div class="clear"></div>
          <input type="submit" name="submit" value="login" class="bt_login" />
          <a class="lost-pwd" href="lost.php">Lost your password?</a>
        </form>
      </div>

















PHP code file "loginBD.php"

<head>
<meta charset="utf-8" />
<title>XXXXX</title>
<!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
<!-- PNG FIX for IE6 -->
<!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
<!--[if lte IE 6]>
        <script type="text/javascript" src="js/pngfix/supersleight-min.js"></script>
        <![endif]-->
</head>
<body>
<?php
try{
        $pdo_options[PDO::ATTR_ERRMODE]=PDO::ERRMODE_EXCEPTION;
        $bdd=new PDO('mysql:host=localhost;dbname=Site_location', 'root', '' , $pdo_options);
}
CATCH(exception $e)
{
die('erreur : ' . $e->getmessage());
}
    if( isset($_POST['login']) && isset($_POST['mdp']) ){
        $mdp = mysql_real_escape_string(($_POST['mdp']));
        $login = mysql_real_escape_string($_POST['login']);
        // Vérification des identifiants
        $req = $bdd->prepare('SELECT id FROM utilisateurs WHERE login = :login AND mdp = :mdp');
        $req->execute(array(
        'login' => $login,
        'mdp' => $mdp));

        $resultat = $req->fetch();
        if (!$resultat)
        {
        echo "0";
        }
        else
        {
        echo "1";
        /*session_start();
        $_SESSION['id'] = $resultat['id'];
        $_SESSION['login'] = $login;
        setcookie('login', $_POST['login'], time() + 365*24*3600, null, null, false, true);*/
        }
    }
?>
</body>















































JQuery - Ajax

<code type="javascript">
<!-- jQuery - the core -->
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<!-- Sliding effect -->
<script src="js/slide.js" type="text/javascript"></script>




<!-- connexion script -->
<script type="text/javascript">
    $(document).ready(function(){
        $("#formLogin").submit(function(){   
            $.post(
               "loginBD.php",
               {
               login : $("#login").val(),
               mdp : $("#mdp").val(),
               },
               function(data){
                                         if(data1 !== "1")
            {
            $(".errorlog").empty().append("try again ...");
            }
            else
            {
                $(".reponselog").hide().append(login + "connexion ok !").show();
                $("#formLogin").hide();
            }
            }
    );
    return false;
});
});
</script>
























I'm testing my code and can not find the cause of not interpreting the result, firebug gives me a log without problem variables are sent, processed by the PHP, the response is good (1 or 0) and s' appears in the panel above the JQuery form during test. But the script refuses to associate the correct sentence and the result shows that consistently bad input when I remove tags test

Firebug report:
POST :





login=TOTO&mdp=TOTO
Response : 
<!doctype html> <html> <head> <meta charset="utf-8"> </head> <body> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Document sans titre</title> </head>  <body> </body> </html>1</body> </html> (i think is due to php includes)
HTML : 1 (with the good login and password regiser in DB)


as it seems to me the problem lies in the interpretation of the php return (1 or 0) by js, I tried to determine the type of the data received with a typeof (): a string.
I then change back with:


function(data){
            var data1 = parseInt("data",10);
            if(data1 !== "1")
            {


with a test : alert typeof () makes it clear that data is a string and data1 is a number
I changed
the conditional to processes data1 (int) but the result will still not be interpreted !!!

thank you for your help I'm a little distraught.

(sorry for my english i'm french !,  google.translate help me a bit XD )