Jump to content

[SOLVED] MySQL 'INSERT' Issues ...


bsamson

Recommended Posts

I have a table within the database, nnyserve_main. The table is called: ebdopt. I have 3 fields, id, cat, and option.

 

I keep getting the following syntax 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 'option) VALUES ('', 'Data Services', '453')' at line 1

 

Here's the script:

 

<?

$cat = "Data Services";
$option="453";

// connection information
$hostName = "localhost";
$userName = "nnyserve_main";
$password = "MYPASSWORDHERE";
$dbName = "$dbname";

// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");

mysql_select_db($dbName) or die( "Unable to select database $dbName");

mysql_query("INSERT INTO ebdopt(id, cat, option) VALUES ('', '$cat', '$feature')") or die (mysql_error()); 
?>

 

I am running MySQL version: 5.0.37 w/ php 5.

 

For the life of my I cannot find the error! Any assistance would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/56430-solved-mysql-insert-issues/
Share on other sites

option is a reserved keyword, and as such, cannot be used as a field name.  while it may not trip up the table creation query, it will trip up any data manipulation statements involving that field.

 

http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html

 

PS:  when wanting to let MySQL assign an ID automatically, you can just drop it from the INSERT statement rather than sending it an empty value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.