mysql - 如何修复我的 express POST 处理程序中的 SQL 语法错误?
问题描述
第一次在这里发帖。
每当我使用代码中的处理程序发送发布请求时,我都会不断收到以下错误。
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check that manual that corresponds to your MariaDB server version for the right syntax to use near '1)' at line 1.
app.post('/',function(req,res,next){
var context = {};
pool.query("INSERT INTO workouts (`name`, `reps`, `weight`,`date`, 'lbs') VALUES (?, ?, ?, ?, ?)", [req.body.name, req.body.reps, req.body.weight, req.body.date, req.body.lbs], function(err, result){
if(err){
next(err);
return;
}
context.results = "Inserted id " + result.insertId;
res.render('table', context);
});
我正在为一个课程项目做这个,我无法弄清楚问题是什么。谢谢您的帮助!
更新:显然,我需要将日期更改为“YYYY-MM-DD”格式。谢谢您的帮助!
解决方案
显然它是 MariaDB 或 MySQL,看起来你在 lbs 周围有单引号。从单引号'
INSERT INTO workouts (`name`, `reps`, `weight`,`date`, **'lbs'**)
支持引号`
INSERT INTO workouts (`name`, `reps`, `weight`,`date`, `lbs`)
推荐阅读
- java - 如何在 Android Studio 中除 MainActivity 之外的其他类中调试?
- reactjs - 状态存在但未发生函数错误。this.setState 不是函数
- java - 在黄瓜特征文件中并行运行场景,一次一个特征文件
- actions-on-google - 不能在不是使用自定义类别创建的项目中指定自定义操作
- android - 批准 Android 上的后台定位?
- pyspark - 如何遍历代码存储库中的 json 文件并增量附加到数据集
- jenkins - 在声明性 Jenkinsfile 中重用并行阶段
- ios - 无法安装最新的 cocoapods 版本
- java - 更新数据库时更新我的 JFrame
- javascript - 如何在反应中多次添加组件onclick?