追查我的 SQL 语法中的错误 [英] Chasing down an error in my SQL syntax

查看:48
本文介绍了追查我的 SQL 语法中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始接触 PHP.我通过阅读和查看有关 PHP 的 tuts 进行自学,主要是将片段剪切和粘贴在一起以实现我的结果.但是,我熟悉 HTML 和 javascript.

I'm just starting out with PHP. I am self-teaching by reading and viewing tuts on PHP and mostly cut and paste snippets together to achieve my results. I am however, familiar with HTML and javascript.

这是我的错误:

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, category, subcategory, date_added, vendor) VALUES('ItemCode','NameofProdu' at line 1

我认为导致这种情况的代码:

The code that I believe causes this:

$sql = mysql_query("INSERT INTO products (part, product_name, units, cost, price, details, group, category, subcategory, date_added, vendor) VALUES('$part','$product_name','$units','$cost','$price','$details','$group','$category','$subcategory',now(),'$vendor')") or die (mysql_error());
 $pid = mysql_insert_id();

看一下 MySQL 表:

Heres a look at MySQL table:

Field           Type               Null

id              int(11)            No       
part            varchar(11)        No       
product_name    varchar(255)       No       
units           int(11)            No       
cost            varchar(16)        No       
price           varchar(16)        No       
details         text               No       
group           varchar(32)        No       
category        varchar(32)        No       
subcategory     varchar(32)        No       
date_added      date               No       
vendor          varchar(32)        No       

我是否忽略了什么?

推荐答案

更改字段名group或用引号括起来,在mysql中为保留关键字.

change the field name group or enclose it with quotes, it is a reserved keyword in mysql.

这篇关于追查我的 SQL 语法中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆