lundi 7 mars 2016

WebSQL - Check database for records (javascript)

I am working on a phonegap app, and have so far set-up the database to which I have the insert and delete function's working correctly.

I am now struggling on checking input values with the data in the database, so for example for now I am just simply attempting to check if any rows are returned, and if there is that will mean the user and pass entered are in the database, if no rows are returned then the user and pass is false.

I am not getting any errors from the sql statement (function errorCB), as well I did put an debug alert within the function LoginSuccess and that worked, however after removing the debug alert in the LoginSuccess function, I do not get prompted with any alerts and instead the page just refreshes.

I have removed the delete and insert functions from the code as it's relevant to this issue.

Any help will be much appreciated.

document.addEventListener("deviceready", onDeviceReady, false);

           var db;

             function onDeviceReady() {
              db = window.openDatabase("DBkhan", "1.0", "SFDatabase", 2*1024*1024);
                         db.transaction(createDB, errorCB, successCB);

                     }

            function createDB(tx) {
   tx.executeSql('CREATE TABLE IF NOT EXISTS mahdi (FirstName text, LastName text, Email text, Password text)');

                     }

                     function errorCB(err) {
                         alert("Error processing SQL: "+err.code);
                     }

                     function successCB() {
                  alert("Database Ready");
                     }

 function loginUser()
         {
        db = window.openDatabase("DBkhan", "1.0", "SFDatabase", 2*1024*1024);
        db.transaction(loginDB, errorCB, LoginSuccess);
        }

        function loginDB(tx)
        {
           var Username = document.getElementById("username").value;
         var Password = document.getElementById("password").value;
         tx.executeSql("SELECT * FROM mahdi WHERE FirstName='" + Username + "' AND Password= '" + Password + "'");

         } function LoginSuccess(tx, results) {
           if (results.rows.length > 0) {
           alert ("User and Pass Found");
           }
           else
           {
           alert ("User and Pass incorrect");
           }

}

Aucun commentaire:

Enregistrer un commentaire