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')
Related
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 (
I am trying to add these value in the "employee" table, but it shows me an error that I can't fix, any help?!
The Syntax:
INSERT INTO `employee`( 'UserName',`ID`, `firstname`, `middlename`,'lastname','Address','department','salary','password','phonenumber','email','LoginStatus')
VALUES ('medo',1','ahdjh','rgetrhytyiu','rgthyu','','2','100000','','24741585285','da#hash.com','1')
The error:
Error: INSERT INTO employee( 'UserName',ID, firstname,
middlename,'lastname','Address','department','salary','password','phonenumber','email','LoginStatus')
VALUES
('medo',1','ahdjh','rgetrhytyiu','rgthyu','','2','100000','','24741585285','da#hash.com','1')
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 ''UserName',ID, firstname,
middlename,'lastname','Address','department','sa' at line 1
Try this:
Remove quotes from column--
INSERT INTO employee( UserName,ID, firstname, middlename,lastname,Address,department,salary,password,phonenumber,email,LoginStatus) VALUES ('medo',1','ahdjh','rgetrhytyiu','rgthyu','','2','100000','','24741585285','da#hash.com','1')
Just remove the (username,ID,......)
Directly write
Insert Into Tablename Values(.....);
And in the Values section you have a ` this in the ID field.Remove that as well.
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())
SQL query i'm running in phpMyAdmin :
INSERT INTO `companies`(`companyId`, `companyName`, `companyImage`)
VALUES ([1],[Example Company],[image.jpg])
phpMyAdmin generates this, i'm just changing the values.
SQL database:
1 companyId int(100)
2 companyName varchar(100)
3 companyImage varchar(100)
Error I get:
#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 '[1],[Example Company],[image.jpg])' at line 1
Use quotes, not brackets, around strings. Integers and floats don't require anything but MySQL allows quotes around those as well.
INSERT INTO `companies`(`companyId`, `companyName`, `companyImage`)
VALUES (1, 'Example Company', 'image.jpg')
Use backticks to escape column and table name.
Use quotes to limit strings.
Use nothing to limit numbers.
Don't use brackets at all in MySQL.
What is the problem with this query?
INSERT INTO acfrac (username,id,count,time) VALUES ("John Smith", 10, 0,2006-06-07 09:44:33.0)
It gives me the following 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 '09:44:33.0)' at line 1
You need to quote your time stamp. In mysql, if the field you're entering is not an integer, it must be quoted.
Try this:
INSERT INTO acfrac (username,id,count,time) VALUES ("John Smith", 10, 0,'2006-06-07 09:44:33.0')
The date and datetime values need to be enclosed in single quotes.