Reputation: 690
I try to enter data into sqlite in cordova, I made one database and one table with two fields was successful, when making three field error occurs when the insert, What is wrong?
This my script with 3 field on 1 table.
$(document).ready(function(){
var db;
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady(){
db = window.sqlitePlugin.openDatabase({name: "samplingapp.db"});
db.transaction(function(transaction) {
transaction.executeSql('CREATE TABLE IF NOT EXISTS sampling_m (id integer primary key, kode_pohon text, bag_pohon text, date text)');
});
}
$("#insert").click(function(){
var kode_pohon=$("#kode_pohon").val();
var bag_pohon=$("#bag_pohon").val();
var date=$("#date").val();
console.log(kode_pohon +""+ bag_pohon +""+ date);
db.transaction(function(transaction) {
var executeQuery = "INSERT INTO sampling_m (kode_pohon, bag_pohon, date) VALUES (?,?)";
transaction.executeSql(executeQuery, [kode_pohon,bag_pohon,date]
, function(tx, result) {
alert('Inserted');
},
function(error){
alert('Error occurred');
});
});
});
});
Upvotes: 1
Views: 106
Reputation: 46
var executeQuery = "INSERT INTO sampling_m (kode_pohon, bag_pohon, date) VALUES (?,?)";
should be
var executeQuery = "INSERT INTO sampling_m (kode_pohon, bag_pohon, date) VALUES (?,?,?)";
so that the date will be saved.
Upvotes: 1