0

I am trying to insert value into sqlite database but I am not able to get success. I am trying to add this value into cordova phonegap application. As this is meant to run as phone app in device so I have put alert in the function to check the flow of the function but unfortunately I am getting only one alert that too of entering into function. Later alerts I am not able to receive.

Here is the code.

function InsertMobileData(){ myDB.transaction(function(transaction) { // Define insert query alert("In") var executeQuery = "INSERT INTO " + "Mobile_Table" + "(device_PhoneNumber) "+ "VALUES(?)"; Helper.log(executeQuery); alert(callingNo); alert(executeQuery); transaction.executeSql(executeQuery, ['"+callingNo+"'] , function(tx, result) { // On success alert("Mobile Number Inserted Successfully"); }, function(error){ // On error alert("Error while inserting data"); }); }); } 

Please help me to correct the code. Thanks.

2
  • did you get the result of alert(callingNo); and alert(executeQuery);? Commented Dec 1, 2014 at 5:22
  • @ekad I am getting only one alert message i.e alert("In").After that i am not getting any alert messages.. Commented Dec 1, 2014 at 5:27

3 Answers 3

2

First thing is syntax error in your code here "transaction.executeSql(executeQuery, ['"+callingNo+"']" You can try by this code its working...

function InsertMobileData(){ myDB.transaction(function(transaction) { var executeQuery = "INSERT INTO Mobile_Table (device_PhoneNumber) VALUES('"+callingNo+"')"; transaction.executeSql(executeQuery, [] , function(tx, result) { // On success alert("Mobile Number Inserted Successfully"); }, function(error){ // On error alert("Error while inserting data"); }); }); } 
Sign up to request clarification or add additional context in comments.

Comments

0

Try adding a space after "Mobile_Table" + so it reads

var executeQuery = "INSERT INTO " + "Mobile_Table " + "(device_PhoneNumber) "+ "VALUES(?)"; 

Comments

0

I think sql has no problem, you can use insert into tablename(colname) values(theValue).

You have alert:

alert(callingNo); 

But I didn't see the var callingNo. maybe there is an error here.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.