0

My populateDB method runs well and when I look into the database the values are stored, but when insertQueryDB method is not working when I am trying to insert data from a form so I think my Insert query is wrong but I type it over many times and watch the correct format but it's still not storing the values from the form in the database when I click submit.

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

        }
lifeishard
  • 17
  • 6
  • Are you actually executing the INSERT, or just creating the variable "query" and forgetting to run it? –  Mar 08 '17 at 21:41
  • I probably delete a line when I was pasting here but I am executing it using a transaction tx.executeSql(query,[], insertQuerySuccess, insertQueryFail); thats goes right under the alert line @PhillipXT – lifeishard Mar 08 '17 at 21:43
  • Does the query from the query variable work if you run it directly on the database? And have you tried just `tx.executeSql(query)` without the transaction? Eliminate the pieces one by one and see which one is causing problems. –  Mar 08 '17 at 21:52
  • I execute the query by itself and now its working @PhillipXT – lifeishard Mar 08 '17 at 22:08

0 Answers0