I am trying to create a function that dynamically inserts data into a table:
So far I have tried:
however,when I execute this code, nothing happens ie. no alert. If I comment out the last tx.executesql insertion line ie. the dynamic one everything works fine. How would I have to change that line to make everything work? Please help… Phonegap newbie here.
document.addEventListener("deviceready", onDeviceReady, false);
var tableName;
var db;
var id='14';
var data='Terry had a little lamb little lamb';
// PhoneGap is ready
//
function onDeviceReady() {
db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql(
'INSERT INTO DEMO (id,data') VALUES (?, ?);',
[id,data],
function (transaction, resultSet) {
//success code
alert('sucessful insertion');
},
errorCB
);
}
// Transaction error callback
//
function errorCB(err) {
alert("Error processing SQL: "+err);
}
// Transaction success callback
//
function successCB() {
alert("success!");
}
It seems that you have a trailing single quote after the word “data”: