mardi 22 mars 2016

sqlite select query with javasecript

i test this function for simple login page , but i face problem and i don't know why because i'm sure the code is correct ..

i put alert to check where is the problem , all alert work but the (alert("after select) doesn't work so the problem occur in SELECT statement

can anyone tell me what is the problem please ?

My code

window.addEventListener("load",ready);

 var db = openDatabase("MyApp", "1.0", "Aqarkfirst", 200000);
 
                 function ready(){
        document.getElementById('send_login').addEventListener('click',login);
        }
   

        function login(){
                        

                        var user= document.getElementById("demo-Username").value;
                        var pass= document.getElementById("demo-Password").value;
                
                db.transaction(function (tx) {
         alert("befor select ");
            tx.executeSql("SELECT * FROM user WHERE username=? AND password=?", [user,pass], function (tx, results) {
               alert("After select");
               var len = results.rows.length;
              
                                
                                        if(results.rows.length>0){
                                                alert("Welcom");
                                        }else {
                                alert("ERROR USERNAME OR PASSWORD");
                           }
               
            }, null);
         });






                
        }


HTML code
<form method="post" id="r">
                                                                                <div class="row uniform">
                                                                                
                                                                                        <div class="6u 12u$(xsmall)">
                                                                                                <input type="text" name="demo-Username" id="demo-Username"  placeholder="Username" autofocus />
                                                                                        </div>
                                                                                
                                                                                        <div class="6u$ 12u$(xsmall)">
                                                                                                <input type="Password" name="demo-Password" id="demo-Password"  placeholder="Password" />
                                                                                        </div>
                                                                                        
                                                                                        
                                                                                        <div class="12u$">
                                                                                                <ul class="actions">
                                                                                                        <li><input type="submit" value="Log In" class="special" id="send_login"/></li>
                                                                                                
                                                                                                </ul>
                                                                                        </div>
                                                                                </div>
                                                                        </form>

Aucun commentaire:

Enregistrer un commentaire