Error in your SQL syntax
Posted: Wed Apr 15, 2009 7:45 am
I am working on an insert statement and I am receiving the following error:
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 'pt-23', 'Pencil Makers Inc.', '15.50', 'no 2 pencils', '5' ' at line 20
Can some provide guidance as to why this error is occurring? I have posted the table I'm using the code.
Thank you,
Paul
--------------------------------Database----------------------------------
--------------------php code with sql statement-----------------------------------------------------
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 'pt-23', 'Pencil Makers Inc.', '15.50', 'no 2 pencils', '5' ' at line 20
Can some provide guidance as to why this error is occurring? I have posted the table I'm using the code.
Thank you,
Paul
--------------------------------Database----------------------------------
Code: Select all
mysql> describe item;
+-------------+--------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------------------+-----------------------------+
| id | int(5) | NO | PRI | NULL | auto_increment |
| deleted | int(1) | NO | | 0 | |
| date_insert | timestamp | NO | | 0000-00-00 00:00:00 | |
| date_update | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| category_id | int(5) | NO | | 0 | |
| short_desc | text | YES | | NULL | |
| part_no | text | NO | | NULL | |
| vendor | text | YES | | NULL | |
| unit_price | decimal(5,2) | YES | | NULL | |
| long_desc | text | YES | | NULL | |
| max_qty | int(5) | NO | | 0 | |
| qty | int(5) | YES | | NULL | |
+-------------+--------------+------+-----+---------------------+-----------------------------+
12 rows in set (0.01 sec))--------------------php code with sql statement-----------------------------------------------------
Code: Select all
<?php
require('../include/connect.php');
$category = $_POST[category];
$short_desc = htmlspecialchars($_POST[short_desc]);
$part_no = htmlspecialchars($_POST[part_no]);
$vendor = htmlspecialchars($_POST[vendor]);
$unit_price = $_POST[unit_price];
$long_desc = htmlspecialchars($_POST[long_desc]);
$max_qty = $_POST[max_qty];
$qty = $_POST[qty];
$sql="INSERT INTO item
(id,
deleted,
date_insert,
date_update,
category_id,
short_desc,
part_no,
vendor,
unit_price,
long_desc,
max_qty,
qty)
VALUES
(NULL,
NULL,
NULL,
NULL,
'$category',
'$short_desc,
'$part_no',
'$vendor',
'$unit_price',
'$long_desc',
'$max_qty'
'$qty')";
mysql_query($sql);
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
?>