【发布时间】:2019-08-29 02:15:49
【问题描述】:
我正在尝试使用 html 按钮插入、删除和更新数据库中的数据。为此,我使用了一个由 node express 调用的 pug 页面,并且一切正常。直到我尝试将数据插入我的数据库。所以我的哈巴狗文件中有这个
script(src='editor.js')
...
p Item Type *required*<br/>
input(type="text", id="iType", name="iType")
p Item name *required*<br/>
input(type="text", id="name", name="Name")
p Item price *optional*<br/>
input(type="text", id="price", name="Price")
p Item ABV *optional*<br/>
input(type="text", id="desc", name="ABV")
p Item description *optional*<br/>
input(type="text", id="desc", name="Desc")
button(id="addItemBtn" onclick="updateMenuItem("+document.getElementById('iType').value+","+document.getElementById('name').value+","+document.getElementById('Price').value+","+document.getElementById('ABV').value+","+document.getElementById('Desc').value+")") add
我正在尝试将输入元素的内容传递给 editor.js 中的 javaScript 函数
function updateMenuItem (itype,name,price,abv,desc) {
//set up connection variables for the sql query
var conn = new sql.ConnectionPool(sqlconfig);
var sqlreq = new sql.Request(conn);
//initiate the connection
conn.connect(function (err) {
//throw an error if the page cannot connect to the server
if (err) {
console.log(err);
return;
}
//
sqlreq.query("insert into food '"+itype+"','"+name+"','"+price+"','"+abv+"','"+desc+"'"), function () {
console.log('OK')
};
})
};
我在这里做错了什么?
【问题讨论】:
标签: javascript node.js express pug