Manikandan
Manikandan

Reputation: 488

Error in authenticating the database in sqlite using jquery

I have created a login page with username and password and if I click the login button it should check if the entered username and password matches with the database(websql) and if it is successfull should go to the next page

HTML:

<label for="uname"> Username :</label>
<input name="uname" type="text" id="username" placeholder="your user name" size="20" maxlength="20" width="20"/>

<label for="pass"> Password :</label>
<input name="password" type="password" id="pass" placeholder="your password" size="20"  maxlength="20"  width="20"/>
<a href="page3.html"  type="submit" class="ui-btn ui-btn-inline ui-corner-all ui-btn-b"  id="check"  onclick="loginRecord()" >check </a>

Jquery Function

$(document).ready(function()
{
$("#check").click(loginRecord);
});

function loginRecord(){

db.transaction(function(tx){
         var user=$('#username').val();
         var pwd=$('#pass').val();       
         var x='SELECT * FROM login WHERE username="+user+"  AND password="+pwd+"'; //to get the username and password from the login table
         tx.executeSql(x,[],function(tx,result){
                   var length=result.rows.length;
           for (i=0;i<rows.length;i++){
                     var res=result.rows.item(i);
                     var username=res.username;
                     var password=res.password; 
           }
            alert("Username : " +  username);
            alert("Password: " + password); 
          // $("#username").html(username);
         //  $("#pass").html(password);
    });
});
}

Is this correct or should I use some additional methods or steps

If this is not correct may I have a coding to authenticate username and password in sqlite using Jquery/Javascript

Upvotes: 1

Views: 375

Answers (2)

Manikandan
Manikandan

Reputation: 488

The coding was this:

     function loginRecord(){

     db.transaction(function(tx){
     var user=$('#username').val();
     var pwd=$('#pass').val();       
     var x="SELECT * FROM login WHERE username='"+user+"' AND password='"+pwd+"' "; 
     tx.executeSql(x,[],function(tx,result){
      if (result.rows.length > 0){

       // alert("Username : " +  result.rows[0].username);
        //alert("Password: " + result.rows[0].password); 
        alert("Hello " +user);
        alert("your password is " +pwd);
      }else{
        alert("Invalid user!");
      }
      });
      });
      }

Upvotes: 1

Abubakar Siddiq Ango
Abubakar Siddiq Ango

Reputation: 138

Try Using the following:

var x="SELECT * FROM login WHERE username='"+user+"' AND password='"+pwd+"' ";    
tx.executeSql(x,[],function(tx,result){
          if (result.rows.length > 0){

            alert("Username : " +  result.rows[0].username);
            alert("Password: " + result.rows[0].password); 
          }else{
            alert("User not found!");
          }
    });

Upvotes: 2

Related Questions