MySQL错误:1064(您的SQL语法有错误;请查看与您的MySQL对应的手册


MySQL Error: 1064 (You have an error in your SQL syntax; check the manual that corresponds to your MySQL

MySQL错误:1064(您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获得在第1行的")"附近使用的正确语法)会话已停止。

$sql =  "INSERT INTO ". GALLERY_MASTER
            .   "(gallery_title,gallery_code, gallery_images,gallerycat_id, gallery_description,gallery_status) "
            .   " VALUES ( "
            .   " '".   $post['gallery_title']              .       "', " 
            .   " '".   $post['gallery_code']               .       "', " 
            .   " '".   $file                           .       "', " 
            .   " '".   $post['gallery_cat_id']         .       "', "
            .   " '".   $post['gallery_description']        .       "', " 
            .   " '".   $post['gallery_status']         .       "', " 
            .   " )"; 

无效SQL:

INSERT INTO 
GALLERY_MASTER(gallery_title,gallery_code, gallery_images,gallerycat_id, gallery_description,gallery_status) 
VALUES ( 'image1', '021', '201411050700381463949438_img3.jpg', '4', '', '1', )

在查询的末尾有一个额外的,

复制此代码

$sql = "INSERT INTO " . GALLERY_MASTER . "(gallery_title,gallery_code, gallery_images,gallerycat_id, gallery_description,gallery_status) " . " VALUES ( " . " '" . $post['gallery_title'] . "', " . " '" . $post['gallery_code'] . "', " . " '" . $file . "', " . " '" . $post['gallery_cat_id'] . "', " . " '" . $post['gallery_description'] . "', " . " '" . $post['gallery_status'] . "' " . " )";

根据错误消息,问题是括号前末尾的附加逗号

Invalid SQL: INSERT INTO GALLERY_MASTER(gallery_title,gallery_code, gallery_images,gallerycat_id, gallery_description,gallery_status)
VALUES ( 'image1', '021', '201411050700381463949438_img3.jpg', '4', '', '1', )
---------------------------------------------------------------------------^

您需要使用以下代码将其删除

$sql = "INSERT INTO ". GALLERY_MASTER . "(gallery_title,gallery_code, gallery_images,gallerycat_id, gallery_description,gallery_status) " . " VALUES ( " . " '". $post['gallery_title'] . "', " . " '". $post['gallery_code'] . "', " . " '". $file . "', " . " '". $post['gallery_cat_id'] . "', " . " '". $post['gallery_description'] . "', " . " '". $post['gallery_status'] . "' " . " )";