插入查询不起作用,但填充方法在PhoneGap中有效

时间:2017-03-08 21:34:13

标签: javascript cordova phonegap-build

我的populateDB方法运行良好,当我查看数据库时存储的值,但当我尝试从表单中插入数据时,insertQueryDB方法不起作用,所以我认为我的插入查询是错误的,但我输入了很多次,看到正确的格式,但是当我点击提交时,它仍然没有将表格中的值存储在数据库中。

function populateDB(tx) {
            //navigator.notification.alert("Start Populating");
            tx.executeSql('DROP TABLE IF EXISTS dataEntryTb');
            tx.executeSql('CREATE TABLE IF NOT EXISTS dataEntryTb (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, activityName TEXT NOT NULL, location TEXT NOT NULL, time NOT NULL, date NOT NULL, reporter NOT NULL)');
            tx.executeSql('INSERT INTO dataEntryTb ( activityName, location, time, date, reporter) VALUES ( "Tony", "tony@testgmail.com", "5555", "today", "james")');
            tx.executeSql('INSERT INTO dataEntryTb ( activityName, location, time, date, reporter) VALUES ( "d", "d@testgmail.com", "5555", "today", "james")');
            //navigator.notification.alert("Finished Populating");
        }



insertQueryDB METHOD
function insertQueryDB(tx) {
            var an = document.forms["myForm"]["activityName"].value;
            var l = document.forms["myForm"]["location"].value;
            var t = document.forms["myForm"]["time"].value;
            var d = document.forms["myForm"]["date"].value;
            var r = document.forms["myForm"]["reporter"].value;
            var query = 'INSERT INTO dataEntryTb ( activityName, location, time, date, reporter) VALUES ( "'+an+'", "'+l+'", "'+t+'", "'+d+'", "'+r+'")';
            navigator.notification.alert("Retrieved the following: Activity Name="+an+" and Location="+l);

tx.executeSql(query,[],insertQuerySuccess,insertQueryFail);

        }

0 个答案:

没有答案