This question already has an answer here:
The 'group' column somehow causes a syntax error
                                
                                    (1个答案)
                                
                        
                                5年前关闭。
            
                    
我正在使用自定义CMS并尝试插入值

结果查询工作正常,但result2查询开始出现错误

即使我尝试在同一查询中添加它,但仍然给我相同的错误

            $sname=addslashes($_POST['sname']);
            $descr=mysql_real_escape_string($_POST['descr']);
            $eve_format=mysql_real_escape_string($_POST['eve_format']);
            $name=mysql_real_escape_string($_POST['name']);
            $pbm=mysql_real_escape_string($_POST['pbmstat']);
             $group=$_POST['group'];
            $feat_img=mysql_real_escape_string($_POST['feat_img']);
        $query="INSERT INTO events (descr,name,eve_format,prize1,prize2,eve_sname) VALUES ('".$descr."','".$name."','".$eve_format."','".$prize1."','".$prize2."','".$sname."')";
        $result=mysql_query($query) or die(mysql_error());
        $qry2="INSERT INTO events (group) VALUES ('".$group."')";
        $result2=mysql_query($qry2) or die(mysql_error());


我得到的错误是

 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 'group) VALUES ('1')' at line 1


我无法弄清楚那边出了什么问题

我认为那边没有语法错误

最佳答案

您的提示已经在突出显示的MYSQL错误上。

right syntax to use near 'group)


因为group是mysql保留字。

您需要用反引号将其包裹起来

`group`


强制性说明:


  Please, don't use mysql_* functions in new code。它们不再维护and are officially deprecated。看到red box吗?而是了解有关prepared statements的信息,并使用PDOMySQLi-this article将帮助您确定哪个。如果选择PDO,则here is a good tutorial
  
  参考:https://stackoverflow.com/a/12860140/3859027

关于php - MySql可以插入值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27372844/

10-10 09:01