简体   繁体   English

用于插入的PHP SQL语法错误

[英]PHP SQL syntax error for insert into

I have a bunch of php files corresponding to an application I am writing, using MySQL for my database structure. 我有一堆与正在编写的应用程序相对应的php文件,使用MySQL作为数据库结构。 I know this questions has been asked before but I've been through most of the posts about it and can't find something that will help... 我知道这个问题以前曾被问过,但我浏览过有关它的大多数文章,却找不到任何有帮助的东西...

In my PHP file I have a SQL query 在我的PHP文件中,我有一个SQL查询

$group_sql = "INSERT INTO group (name, description, ownerEmail) VALUES ('$groupName', '$descrip', '$owner')";

that corresponds to a group table with three attributes: name, description, and owner email. 与具有三个属性的组表相对应:名称,描述和所有者电子邮件。 $groupName, $descrip, $owner are three variables I have defined. $ groupName,$ descrip,$ owner是我定义的三个变量。 I'm getting this syntax error when I try to run the query: 当我尝试运行查询时出现此语法错误:

Error: INSERT INTO group(name, description, ownerEmail) VALUES(hi, hi, test@example.com) You have an error in your SQL syntax; 错误:INSERT INTO组(名称,描述,所有者电子邮件)VALUES(嗨,嗨,test @ example.com)您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group(name, description, ownerEmail) VALUES(hi, hi, test@example.com)' at line 1 在第1行的'group(name,description,ownerEmail)VALUES(hi,hi,test@example.com)'附近使用与MySQL服务器版本相对应的手册以获取正确的语法

Can someone please help me see what I'm doing wrong? 有人可以帮我看看我在做什么错吗?

GROUP is a MySQL reserved keyword . GROUPMySQL的保留关键字 If you name a table that, then you must wrap it in ticks: 如果命名一个表,则必须将其包装在刻度中:

$group_sql = "INSERT INTO `group` (name, description, ownerEmail)  
              VALUES ('$groupName', '$descrip', '$owner')";

Notice where SQL starts with the error and points to it? 注意到SQL在哪里以错误开头并指向错误?

>for the right syntax to use near 'group  
>                                 ^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM