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.
Related
Query that I have used is:
DROP TABLE IF EXISTS `category`;
CREATE TABLE IF NOT EXISTS `category` (
`category_id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(50) NOT NULL,
`category_status` enum('0','1') NOT NULL,
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `category`
--
INSERT INTO `category` (`category_id`, `category_name`, `category_status`) VALUES
(1, 'Flu & Cold', '1'),
(2, 'Vitamins & Supplements', '1'),
(3, 'Chickenpox', '0');
This query executes successfully initially but when I tend to browse the table,
this error shows up
#1064 - 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 'CREATE TABLE IF NOT EXISTS category ( category_id int(11) NOT NULL AUT...' at line 2
enter image description here
I am using xampp 8.1.4-1.
But I can view the structure of the table
enter image description here
SELECT * FROM category
shows all the rows of the category table.
I figured this is not an error.[Even though I cannot access the category table inside the PHPMYADMIN. ]
Thanks.
Any suggestions are welcomed.
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`, ...
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;
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?