【问题标题】:MySQL Error: 1064 (You have an error in your SQL syntax; check the manual that corresponds to your MySQLMySQL 错误:1064(您的 SQL 语法有错误;请查看与您的 MySQL 对应的手册
【发布时间】:2014-11-05 08:16:59
【问题描述】:

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', )

【问题讨论】:

  • 去掉 ) 之前的最后一个 )
  • @Niraj7878 在发布之前格式化代码,并将其适当地标记到您的 DBMS。

标签: php mysql sql


【解决方案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'] . "' " . " )";

【讨论】:

    【解决方案2】:

    根据错误信息,问题在于右括号前末尾的附加逗号

    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'] . "' " . " )"; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      • 2014-03-14
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多