所以基本上,我有一个存储这个特定值的JavaScript变量,我需要将这个变量放在MySQL查询语句中。
源代码:
var Pollution_Reading = 25;DatabaseConnection.query('INSERT INTO Air_Pollution_Record (Air_Pollution_Reading) VALUES ('"Pollution_Reading"')');
var Pollution_Reading = 25;
DatabaseConnection.query('INSERT INTO Air_Pollution_Record (Air_Pollution_Reading) VALUES ('"Pollution_Reading"')');
我已经尝试了我知道的所有方法,但我仍然无法将变量保存的值插入到数据库中。我该怎么办?
eiee3dmh1#
DatabaseConnection.query('INSERT INTO Air_Pollution_Record (Air_Pollution_Reading) VALUES ('+Pollution_Reading+')');
jpfvwuh42#
试着这样做:
//reading post dataconst useremail = req.body.useremail;const password = req.body.password;//save into db startvar sql = "INSERT INTO `users` (`UserName`, `UserPassword`) VALUES ('"+useremail+"','"+ password+"')";
//reading post data
const useremail = req.body.useremail;
const password = req.body.password;
//save into db start
var sql = "INSERT INTO `users` (`UserName`, `UserPassword`) VALUES ('"+useremail+"','"+ password+"')";
2条答案
按热度按时间eiee3dmh1#
jpfvwuh42#
试着这样做: