前端发起请求,修改数据表中的数据,修改的选项数量不定,内容不定,代码如下。为什么操作失败?提示
{"ret":"0","msg":"fail","data":{"code":"ER_PARSE_ERROR","errno":1064,"sqlState":"42000","index":0}}
Mysql代码:
activity:{
u_activity:'update tb_banner set ? where id=?'
后端接收post请求:
router.post('/', (req, res) => {
var body = req.body;
var params = body.params;
var cmd = body['cmd'];
if(!cmd){
fronntReq(res,'Unrecognized CMD!');
return false;
if(cmd == 'edit'){
var setKey = 'status='+params.status;
console.log(setKey)
console.log(body.id)
// var sql = 'update tb_banner set '+setKey+' where id='+body.id
conn.query($sql.activity.u_activity,[setKey,body.id], function(err, result, fields) {
console.log(err)
if (err) jsonErr(res,err)
if(result){
updataBannerPosition();
jsonWrite(res, result);
前端发送post请求:
{cmd: "edit", id: 1, params: {status: 1}}