0

我正在尝试使用 javascript 中的 vars 构建一个 sql 语句字符串。

我得到了这一行代码

     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 + ")" + "'";

我的谷歌浏览器开发工具控制台抛出这个错误并指向上面的行

Uncaught SyntaxError: Unexpected identifier 

抛出此错误的任何原因?所有变量都是有效的。

4

1 回答 1

1

尝试这个。你在两个地方错过了 + 和一个额外的逗号......

 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 + ")" + "'";
于 2013-06-06T20:45:56.390 回答