Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Sam_Suresh
Beginner
128 Views

Login Local Storage Error

I'm creating a login interface in Intel XDK for a mobile app. When I hit login, I'm getting alert "login error". Username and password is exist in MySQL db but cant login.

HTML login form

<input type="text" placeholder="Email" id="email">
<input type="password" placeholder="Password" id="pass">
<button class="button widget uib_w_13 d-margins button-positive button-clear" id="login" data-uib="ionic/button" data-ver="0">Login</button>

Javascript

 $(document).on("click", "#login", function(evt)       
{

    var email=$("#email").val();
    var pass=$("#pass").val();
    var dataString="email="+email+"&pass="+pass+"&login=";
    if($.trim(email).length>0 & $.trim(pass).length>0)
    {
        $.ajax({
            type: "POST",
            url: 'http://localhost/signup.php',
            data: dataString,
            crossDomain: true,
            cache: false,
            beforeSend: function(){ $("#login").html('Connecting...');},
            success: function(data){
                if(data=="success")
                {
                    localStorage.login="true";
                    localStorage.email=email;
                    activate_page("#userpage"); 
                }
                else(data="failed");
                {
                    alert("Login error");
                    $("#login").html('Login');
                }
            }
        });
    }
     return false;
});

PHP Code

if(isset($_POST['login']))
{
    $email=mysql_real_escape_string(htmlspecialchars(trim($_POST['email'])));
    //example pass. do not use without bcrypt
    $pass=mysql_real_escape_string(htmlspecialchars(trim($_POST['pass'])));
   

    $login=mysql_num_rows(mysql_query("select * from `login` where `email`='$email' and `pass`='$pass'"));
    if($login!=0)
    {
        echo "success";
    }
    else
    {
        echo "failed";
    }
}

Any help appreciated. Thank you

Tags (2)
0 Kudos
5 Replies
jerome_g_2
Beginner
128 Views

"http://localhost/signup.php"

Are you sure you're using the correct localhost url ? Where's the port number ? ;). localhost:3003/signup.php for instance check your IDE or your TOMCAT/Wamp configuration in order to get the correct URL.

Sam_Suresh
Beginner
128 Views

That is correct URL.

I able to register user with same URL. But not able to login. I think there is problem with datastring.

Diego_Calp
Valued Contributor I
128 Views

Hi Sam,

Could be that you are passing in the datastring an empty login variable? Then isset($_POST['login']) evaluates to false.

Try something like this:

var dataString="email="+email+"&pass="+pass+"&login=1";

Regards,

Diego

Sam_Suresh
Beginner
128 Views

Thank you for pointing that out.

I still cant login.. It stopped at connecting... Is my redirect after login is correct?

Diego_Calp
Valued Contributor I
128 Views

Hi Sam,

The redirect, are you talking about the activate_page? Seems OK to me, but sometimes XDK needs a tweak to have it working.

Take a look to jquery ajax documentation, I saw some examples where you need to add the event complete to remove what are you doing in the beforeSend.

Another suggestion is to place a console.log in your code to know if now it is entering into the success section of the ajax call, then see what happens with activate_page.

Regards

Diego

 

 

Reply