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.
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')
Where is the error in this query?
INSERT INTO chat (`id`,`user`,`message`,`date`)
VALUES (null,'user','test',CURRENT_TIMESTAMP);
This is the error message I receive:
"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 ''id','user','message','date') VALUES (null,'user','test',CURRENT_TIMESTAMP)' at line 1"
if the id is autoincrement then use this instead
INSERT INTO `chat` (`user`,`message`,`date`)
VALUES ('user','test',NOW());
Its difference between single quote ' and backtick `
I am trying to insert data from a csv file into mysql using BigDump.
It stops on line 2, with the error:
"Query: INSERT INTO location VALUES
(1,"O1","","","",0.0000,0.0000,, );
MySQL: 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 ' )' at line 1"
If I run the statement from withing phpmyadmin, it says:
"#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 ' )' at line 1"
What can I do to make the data get into the database?
Thank you.
The commas with no values looks sketchy to me.
INSERT INTO location VALUES (1,"O1","","","",0.0000,0.0000,, );
should probably be
INSERT INTO location VALUES (1,"O1","","","",0.0000,0.0000,NULL,
NULL);
Does your insert statement contain values for every column in the table? If not, you have to name the columns.
For example,
insert into location (col1, col2, col3) values (1, 2, 3);
If you show us the structure of the LOCATION table you can get better answers.