Error in your SQL syntax

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

Error in your SQL syntax

Post by pauldr »

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----------------------------------

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());
  }
 
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Error in your SQL syntax

Post by Christopher »

You are missing a closing single quote on line 32 in the PHP above.
(#10850)
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

Re: Error in your SQL syntax

Post by pauldr »

Thank you for second set of eyes.

Paul
Post Reply