Mysql error in my syntax [duplicate] - mysql
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 7 years ago.
Hey i have an error in my mysql syntax, and i dont know why i get it. I can't see an error in my code and i have checked the web for help...
INSERT INTO downloads_log
(file,by,time) VALUES
(1,1, NOW())
The error:
'SQLSTATE[42000]: Syntax error or access violation: 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 'by, time) VALUES (1,1,NOW())
by,file and time are reserved keywords used in MYSQL. Use a back tick (`) to escape the keywords in your query. Change your query to :
INSERT INTO downloads_log
(`file`,`by`,`time`) VALUES
(1,1, NOW())
by is a reserved keyword. Try:
INSERT INTO downloads_log
(`file`, `by`, `time`) VALUES
(1, 1, NOW())
You're using reserved keywords as column names. Try to avoid using reserved keywords as column names, but if you haven't choice you have to pass them to backticks `` in following:
INSERT INTO downloads_log (`file`,`by`,`time`) VALUES (1,1, NOW())
Related
MySQL select command with a column named "set" [duplicate]
This question already has answers here: Select a column with a keyword name (6 answers) Closed 1 year ago. I would like to select some parameters in a column of my database. The issue that I have is that the column where I want to select the data is named "set". SELECT * FROM database.table where set=5130; "Set" is also a keyword in MySQL which leads to an error : Error Code: 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 'set=5130' at line 1 How should I bypass this issue ?
I guess changing the column name is not an option for you. Then you need to use backticks (`). SELECT * FROM database.table where `set`=5130;
The best approach would probably be to rename the column. If this is not an option, you can escape it by surrounding it with backticks: SELECT * FROM database.table WHERE `set` = 5130; -- Here ---------------------------^---^
MySQL syntax error, underscore
Executing this query INSERT INTO classes( '_fkUserID', 'date', 'time' ) VALUES ( '1', '2017-07-04', '8:15' ) gives me the following 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 ''_fkUserID', 'date', 'time') VALUES ('1', '2017-07-04', '8:15')' at line 1 I'm assuming the error has something to do with parsing the underscore, but I can't manage to find a way around it.
Change classes('_fkUserID', 'date', 'time') To classes(`_fkUserID`, `date`, `time`) Single quotes makes the fields as strings You don't necessarily need to add the backticks on the column names unless they are Reserved Words to the MySql. In your sql statement, date and time are reserved words, so you must use the backticks on it, which means that it would also work as: classes(_fkUserID, `date`, `time`) Backticks are Identifier Quote Characters which means that its purpose is to make MySql understand that it should identify whatever is within it as an identifier, in your case a column name.
It is actually: INSERT INTO classes(_fkUserID,date,time) VALUES ( '1', '2017-07-04', '8:15' )
Try removing the single quotes and use back tick symbol instead (
can someone tell me what i am doing wrong with this sql code [duplicate]
This question already has answers here: How to select a column name with a space in MySQL [duplicate] (6 answers) Closed 7 years ago. Insert into DonutOrder (Date, Special Handling Notes) Values ("20140506", "Please Include Plates and Napkins"); I keep getting this response Error SQL query: Insert into DonutOrder (Date, Special Handling Notes); MySQL said: Documentation #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 'Handling Notes)' at line 1
Well, your identifier (column name) has spaces, so you should escape it with backticks: insert into `DonutOrder` (`Date`, `Special Handling Notes`) Values ("20140506", "Please Include Plates and Napkins");
mysql insert from select query returning syntax error [duplicate]
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. So, I run an online imageboard and I am updating to a newer imageboard software. Rather than manually enter the board information for each new imageboard, I wanted to just port over the fields I need from the old table to the new one, but PHPMYADMIN is giving me a mysql syntax error and I don't know what the problem is: INSERT INTO `tryboards` (uri, title) SELECT name, desc FROM `aasboards`; This should move the data from the old table to the new, yes? The aasboards table has several columns I want to omit. The tryboards table contains 3 fields, the 3rd one being subtitle, which is nullable and shouldn't be needed for this query. EDIT: the error is as follows: Error SQL query: Documentation INSERT INTO tryboards ( uri, title ) SELECT name, DESC FROM aasboards MySQL said: Documentation 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 FROM aasboards' at line 2
desc is a reserved word: INSERT INTO `tryboards` (uri, title) SELECT name, `desc` FROM `aasboards`;
You have an error in your SQL syntax
I am getting this 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 '"insert into hall_booking(name,address,event_type,hallNo,arrival_time,arrival_da' at line 1 When running this query: insert into hall_booking ( name,address,event_type,hallNo,arrival_time,arrival_date,dep_time,dep_date,identity,emailid,contact,total_members,desc,catering,service,decoration,other ) values ( '$nm','$add','$typ','$roomno','$arrv','$arrivaldate','$departure','$dDate','$idt','$emailid','$cont','$desc','200','200','200','200') Again a problem occured in sql statement. What mistake i did?
You look as if you're using protected keywords as column names (you shouldn't really do this). Try escaping them with ` insert into hall_booking ( name,address,event_type,hallNo,arrival_time, arrival_date,dep_time,dep_date,`identity`, emailid,contact,total_members,`desc`,catering,service,decoration,other) values( '$nm','$add','$typ','$roomno','$arrv', '$arrivaldate','$departure','$dDate','$idt', '$emailid','$cont','$desc','200','200','200','200')
Try this: insert into hall_booking (name,address,event_type,hallNo,arrival_time,arrival_date,dep_time,dep_date,identity,emailid,contact,total_members,desc,catering,service,decoration,other) values ( '".$nm."','".$add."','".$typ."','".$roomno."','".$arrv."','".$arrivaldate."','".$departure."','".$dDate."','".$idt."','".$emailid."','".$cont."','".$desc."','200','200','200','200')"
You are getting this error because you are using a reserved keyword desc as a column name. To overcome this error you can replace your query with the following one: insert into hall_booking (name,address,event_type,hallNo,arrival_time,arrival_date,dep_time,dep_date,`identity`,emailid,contact,total_members,`desc`,catering,service,decoration,other) values ('$nm','$add','$typ','$roomno','$arrv','$arrivaldate','$departure','$dDate','$idt','$emailid','$cont','$desc','200','200','200','200')" Also you can refer this article for more clarification: How do I escape reserved words used as column names? MySQL/Create Table
I think you have not mentioned last value "INSERT INTO `hall_booking`(`name`,`address ,`event_type`,`hallNo`,`arrival_time`,`arrival_date`,`dep_time`,`dep_date`,`IDENTITY`,`emailid`,`contact`,`total_members`,`DESC`,`catering`,`service`,`decoration`,`other`) VALUES('".$nm."', '".$add."', '".$typ."', '".$roomno."', '".$arrv."', '".$arrivaldate."', '".$departure."', '".$dDate."', '".$idt."', '".$emailid."', '".$cont."', '".$desc."', '200', '200', '200', '200', 'Last Value')"
You have a field which is a reserved word... desc. Try to enclosed it with '`' character so it should be `desc`. mysql> insert into hall_booking (name,address,event_type,hallNo,arrival_time, arrival_date,dep_time,dep_date,identity,emailid,contact,total_members, `desc`,catering,service,decoration,other) values ('$nm','$add','$typ','$roomno','$arrv','$arrivaldate','$departure','$dDate', '$idt','$emailid','$cont','$desc','200','200','200','200')