This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
im tearing my hair out over this one. A query is throwing an 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 'FROM, SUBJECT, DATE, READ, MAIL ) VALUES ( 'EJackson', 'dfdf', '1270974101', 'fa' at line 1
I printed out the query to see what could be the problem:
INSERT INTO db.tablename ( FROM, SUBJECT, DATE, READ, MAIL ) VALUES ( 'EJackson', 'dfdf', '1270974299', 'false', 'dfdsfdsfd' )
and finaly the structure consists of:
CREATE TABLE db.tablename (
`ID` int(12) NOT NULL auto_increment,
`FROM` varchar(255) NOT NULL,
`SUBJECT` varchar(255) NOT NULL,
`DATE` varchar(255) NOT NULL,
`READ` varchar(255) NOT NULL,
`MAIL` varchar(255) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I can't find anything wrong. Any help would be much appreciated.
In the insert statement, "FROM" is a keyword in SQL so you need to enclose it in backquotes like you have in your create table statement.
So it'll be like:
INSERT INTO db.tablename (`FROM`, `SUBJECT`, `DATE`, `READ`, `MAIL` ) VALUES ( 'EJackson', 'dfdf', '1270974299', 'false', 'dfdsfdsfd' )
Isn't FROM a reserved word in MySQL?
Related
Below is the block I am trying to execute, the documentation says this should work but instead I am met with an error that states "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO Location_Inventory_Column (Aisle, Name)
SELECT Aisle, Name ' at line 2"
~Any help would be highly appreciated!
START TRANSACTION
INSERT INTO Location_Inventory_Column (`Aisle`, `Name`)
SELECT `Aisle`, `Name` FROM TMPTableImport
Table Inserting Into:
CREATE TABLE `Location_Inventory_Column` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`Aisle` INT(11) NOT NULL DEFAULT 0,
`Name` VARCHAR(50) NOT NULL,
`Description` VARCHAR(50) NULL DEFAULT NULL,
`Disabled` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
TMPTable contains only Aisle and Name columns (See image)
TMPTABLE Image
As mentioned by #Akina the statement "START TRANSACTION" was the cause as it did not have a delimiter following the semicolon.
You must remove the single quotes in the Location_Inventory_Column (Aisle, Name) like this:
Location_Inventory_Column (Aisle, Name)
Table schema:
CREATE TABLE IF NOT EXISTS `movie` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`desc` text NOT NULL,
`review` text NOT NULL,
`image_url` text NOT NULL,
`promo_url` text NOT NULL,
`created_on` datetime NOT NULL,
`modified_on` datetime NOT NULL,
PRIMARY KEY (`id`)
)
Insert statement:
INSERT INTO movie (name, desc, review, image_url, promo_url, created_on, modified_on) VALUES ('?p0', '?p1', '?p2', '?p3', '?p4', '?p5', '?p6')
Error:
#1064 - 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 'desc, review, image_url, promo_url, created_on, modified_on) VALUES ('?p0', '?p1' at line 1
I am not able to figure out error source, can anyone please point it out?
desc is a reserved word. Either wrap it in ticks or change it to "description" or any other non-reserved name.
For me the code works. Perhaps the "desc" makes a problem (though you have it in backticks)?
DESC is a reserved word in MySQL.
You can still use it in the table definition, though. Just wrap it in backticks:
(name, `desc`, ...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This is my table definition:
CREATE TABLE IF NOT EXISTS `sms_data_updated` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_sms_received` int(10) unsigned DEFAULT NULL,
`sender_name` varchar(50) NOT NULL,
`sender_number` char(14) NOT NULL,
`key_word` varchar(20) NOT NULL,
`message_content` varchar(160) NOT NULL,
`date_received` datetime NOT NULL,
`date_inserted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`categories` varchar(100) NOT NULL,
`Division` varchar(30) NOT NULL,
`location_name` varchar(80) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
And when use the following INSERT statement:
INSERT INTO sms_data_updated (id_sms_received, sender_name, sender_number, key_word, message_content, date_received, Division, location_name)
VALUES (1,Shahriar Khondokar,+1726740333,,This is message content1. I need help1.,2012-10-16 10:11:09,Barisal,Borishal)
I am getting the following error message:
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 'Khondokar,+8801726740333,,This is message content1. I need help1.,2012-10-16 10:' at line 1
Any idea why?
string values must be wrap with single quote
VALUES(1,'Shahriar Khondokar','+172674033','This is message content1.',...)
Strings like Shahriar Khondoka needs quotes around it. Like this:
INSERT INTO sms_data_updated (id_sms_received, sender_name, sender_number, key_word, message_content, date_received, Division, location_name, Latitude, Longitude)
VALUES (1,'Shahriar Khondokar',rest of columns...)
It looks like you have a hanging comma after the location_name.
You have a different number of values as the amount of rows you are inserting into in the query. This could be causing an issue.
mysql query - 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 'a', '1') ON DUPLICATE KEY UPDATE count=count+1' at line 1
The query that fails:
INSERT INTO tags (ip, tag, count)
VALUES ('xx.xx.xxx.xxx', 'krwiopijcy', '1')
ON DUPLICATE KEY UPDATE count=count+1;
Is there anything wrong in my query?
count is a built in function and as such, may require care to be used as such. However, as the docs say, it is perfectly fine as column name. You might want to escape it using
`count`
That being said, I had no problem with your exact query (no escaping) using this table structure:
CREATE TABLE `tags` (
`ip` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`tag` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`count` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`ip`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Your example from the comments has one apostrophe too much (behind 'umacku'), which doesn't seem to be the problem (as it is not given in the error message), but you should paste the exact queries:
INSERT INTO tags (ip, tag, count)
VALUES ('xx.xx.xxx.xxx', 'umacku'', '1')
ON DUPLICATE KEY UPDATE count=count+1;
INSERT INTO `comments`
( `id`, `pid`, `comment`, `user`, `date`, `active`)
VALUES
('23','3','Most Excellent! I am using it right now as you can see and would never even consider different shopping cart software... I''ve tried them all and found them lacking the freedom to do it my way ;)','Admin','2010-12-08 21:00:07','1');
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 ''Most Excellent! I am using it right now as you can see and would never even co' at line 1
It's got me baffled?! I replaced the single quote for "I've" and I still get the error
PHP 5.3.6
Mysql 5.5.10
DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
`id` int(11) NOT NULL auto_increment,
`pid` int(11) NOT NULL,
`comment` varchar(255) NOT NULL,
`user` varchar(25) DEFAULT '0',
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
);
I can get the exact same error if I break the query this way:
INSERT INTO `comments` ( `id`, `pid`, `comment`, `user`, `date`, `active`) VALUES ('23','3','Most Excellent! I am using it right now as you can see and would never even co
(Tested on MySql 5.1.41.)
I guess the string which contains the query is being broken at position 179~180. Try inspect the query string in your PHP code right before the query execution.