所以基本上,我有这个JavaScript变量存储这个特定的值,我需要将这个变量放在MySQL Query语句中。
源代码:
var Pollution_Reading = 25;
DatabaseConnection.query('INSERT INTO Air_Pollution_Record (Air_Pollution_Reading) VALUES ('"Pollution_Reading"')');
我已经尝试了所有我知道的方式,但我仍然无法将变量所持有的值插入到数据库中。我该怎么办?
答案 0 :(得分:1)
DatabaseConnection.query('INSERT INTO Air_Pollution_Record (Air_Pollution_Reading) VALUES ('+Pollution_Reading+')');
答案 1 :(得分:0)
尝试这样做:
//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 :(得分:0)
您可以尝试这种模板文字的格式。 为您提供简单和干净的代码。
const sql = `INSERT INTO query_form (name, email, query_title, query_description) VALUES ('${name}', '${email}', '${query_title}', '${query_description}')`;