0

I'm trying to build a string of an sql statement using vars in javascript.

I got this line code

     var sql = "'INSERT INTO UPLOADS (poleID, submitDate, poleDamaged, poleDown, wireDown, brokenFixture, brokenBulb, fullname, phonenumber, email, comments, address, city, state, zipcode, lat, lng) VALUES (" + poleID + "," + submitdate + "," + poleDamaged + "," + poleDown + "," + wireDown + "," + brokenFixture + "," + brokenBulb + "," + fullname + "," phonenumber + "," + email + "," + comments + "," + address + "," + city + "," state + "," + zipcode + "," + lat + "," + "," + lng + ")" + "'";

and my Google Chrome dev tools console is throwing this error and pointing to the line above

Uncaught SyntaxError: Unexpected identifier 

Any reason it is throwing this error? All vars are valid.

2
  • Ignore the extra , in the statement. Commented Jun 6, 2013 at 20:42
  • @igor this is executing on their device to a sqlite database. No connection to anyone else except for themselves. Commented Jun 6, 2013 at 20:47

1 Answer 1

1

Try this. you missed + in two places and an extra comma...

 var sql = "'INSERT INTO UPLOADS (poleID, submitDate, poleDamaged, poleDown, wireDown, brokenFixture, brokenBulb, fullname, phonenumber, email, comments, address, city, state, zipcode, lat, lng) VALUES (" + poleID + "," + submitdate + "," + poleDamaged + "," + poleDown + "," + wireDown + "," + brokenFixture + "," + brokenBulb + "," + fullname + "," + phonenumber + "," + email + "," + comments + "," + address + "," + city + "," + state + "," + zipcode + "," + lat + "," + lng + ")" + "'";
Sign up to request clarification or add additional context in comments.

1 Comment

You sir are correct. Sorry for the stupid question. I should've looked over it more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.