日期未插入到数据库的 login_date 字段中。当我在 phpmyadmin 中运行 sql 查询时显示以下错误
1064 - 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 ''user_id','login_date','login_time','logout_date','logout_time')values('12','201' at line 1
提前致谢。
代码:
$date=date("d/m/y", time());
$time=date("H:i:s",time());
$q = $_POST['id'];
$sql1="insert into entries('user_id','login_date','login_time','logout_date','logout_time')values('$q','$date','$time','$date','$time')";
$res1=mysql_query($sql1);
最佳答案
这是因为您在列名周围使用了单引号 '
。列名不是字符串。
你要么不使用任何东西,要么最好使用反引号,`,像这样:
$sql1 = <<< SQL
INSERT INTO `entries` (
`user_id`,
`login_date`,
`login_time`,
`logout_date`,
`logout_time`
) VALUES (
'{$q}',
'{$date}',
'{$time}',
'{$date}',
'{$time}'
)
SQL;
关于php - 日期未插入 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25911074/