这是我的INSERT SQL:
$insert_pg = "INSERT INTO tblPhotoAlbum (photo_album_title, photo_album_date, photo_album_time, photo_album_detail) VALUES ('".$pg_title."', 'STR_TO_DATE('".$pg_date_post."', '%d-%m-%Y')', '".$current_time."' , '".$pg_detail."')";
" STR_TO_DATE"部分,哪个php回显这个mysql错误信息:
Warining: 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 '01/05/2014', '%d-%m-%Y')', '17:24:24' , '
ABC Opening 2014
')' at line 1
答案 0 :(得分:0)
尝试在单引号
中创建查询变量并从'STR_TO_DATE('".$pg_date_post."', '%d-%m-%Y')'
$insert_pg = "INSERT INTO tblPhotoAlbum (photo_album_title, photo_album_date, photo_album_time, photo_album_detail) VALUES ('$pg_title',STR_TO_DATE('$pg_date_post','%Y-%m-%d'), '$current_time' , '$pg_detail')";
或
$insert_pg = "INSERT INTO tblPhotoAlbum (photo_album_title, photo_album_date, photo_album_time, photo_album_detail) VALUES ('".$pg_title."', STR_TO_DATE('".$pg_date_post."', '%Y-%m-%d'), '".$current_time."' , '".$pg_detail."')";
答案 1 :(得分:0)
您的日期格式错误。在mysql中输入日期时,您应该使用YYYY-MM-DD格式:
'-%Y-%m-%d'
插入内容如下所示:
$insert_pg = "INSERT INTO tblPhotoAlbum
(photo_album_title, photo_album_date, photo_album_time, photo_album_detail)
VALUES ('".$pg_title."', '".date('Y-m-d', strtotime($pg_date_post))."', '".$current_time."' , '".$pg_detail."')";
答案 2 :(得分:0)
删除STR_TO_DATE()
函数
$insert_pg = "INSERT INTO tblPhotoAlbum (photo_album_title, photo_album_date, photo_album_time, photo_album_detail) VALUES ('".$pg_title."', STR_TO_DATE('".$pg_date_post."', '%d-%m-%Y'), '".$current_time."' , '".$pg_detail."')";
答案 3 :(得分:0)
这是我的修改,我找到了解决方案。
$insert_pg = "INSERT INTO tblPhotoAlbum (photo_album_title, photo_album_date, photo_album_time, photo_album_detail) VALUES ('".$pg_title."', STR_TO_DATE('".$pg_date_post."','%m/%d/%Y') , '".$current_time."' , '".$pg_detail."')";