在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/數(shù)據(jù)庫  網(wǎng)絡(luò)安全  HTML/ 請(qǐng)教:node.js express mysql存儲(chǔ)文章內(nèi)容(html代碼)代碼

請(qǐng)教:node.js express mysql存儲(chǔ)文章內(nèi)容(html代碼)代碼報(bào)錯(cuò)

**環(huán)境:
node.js express mysql**
問題:
mysql 插入文章數(shù)據(jù)時(shí),存儲(chǔ)文章詳情內(nèi)容時(shí)報(bào)錯(cuò),如下:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://example.com/movies.json')
普通文本內(nèi)容沒問題,但里面出現(xiàn)"代碼片段"好像就報(bào)錯(cuò)。
(是不是得怎么轉(zhuǎn)譯一下,求方法,剛接觸node.js)
語法這么寫得:

insert into article_list
          (title,author,summary,is_top,catalog_alias,content)
           values
            ('${req.body.title}',
            '${req.body.author}',
            '${req.body.summary}',
            '${req.body.is_top}',
            '${req.body.catalog_alias}',
            '${req.body.content}')`;

如圖所示:
圖片描述

回答
編輯回答
任她鬧

不要直接拼接字符串,如果你的內(nèi)容包括以下符號(hào) ' -- [ ] 等 ,可能會(huì)報(bào)錯(cuò),
例如本來你想查詢 select * from table where name = '${var1}';, 如果你的變量var1 是 Mr.W'O,那么拼接后你的語句就變成了 select * from table where name = 'Mr.W'O'; 語句中出現(xiàn)了三個(gè) ' 當(dāng)然會(huì)報(bào)語法錯(cuò)誤。 報(bào)錯(cuò)還是小事情,被黑客利用而進(jìn)行sql注入就麻煩了。
建議你用node的模塊mysql或mysql2 對(duì)變量進(jìn)行編碼,可能你的寫法就變成了這樣

var sql = `insert into article_list
          (title,author,summary,is_top,catalog_alias,content)
           values
            (?,?,?,?,?,?)`;
let result = mysql.query(sql, [req.body.title, req.body.author,req.body.summary,req.body.is_top])
2017年1月6日 00:12