简体   繁体   English

WebSQL-检查数据库中的记录(javascript)

[英]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. 我正在开发一个phonegap应用程序,到目前为止,已经设置了我可以正常使用插入和删除功能的数据库。

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. 我现在正在努力用数据库中的数据检查输入值,所以例如现在,我只是简单地尝试检查是否返回了任何行,如果有的话,这意味着用户和输入的通行证都在数据库中,如果没有返回任何行,则用户和pass为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. 我没有从sql语句中获取任何错误(函数errorCB),也没有在函数LoginSuccess中放置调试警报,并且该警报起作用了,但是在LoginSuccess函数中删除了调试警报之后,我没有收到任何警报的提示而是刷新页面。

I have removed the delete and insert functions from the code as it's relevant to this issue. 我已从代码中删除了delete和insert函数,因为它与此问题相关。

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");
           }

} }

Don't worry, all fixed. 不用担心,所有问题都已解决。 See below if you'd like to see what I changed around. 如果您想了解一下我所发生的变化,请参见下文。 Seem's as though it was the missing array [] in the executesql statement and calling the renderList (changed from loginSuccessful) into the exectutesql statementent. 好像是executesql语句中缺少的数组[]一样,并将renderList(从loginSuccessful更改)调用到exectutesql语句中。

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

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

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM