-1

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?

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Vinita Pawar
  • 89
  • 1
  • 11
  • Are you doing this on the MySQL command line? Also, have you verified your schema? – merlin2011 Mar 14 '14 at 05:34
  • `desc` and `identity` are keywords in sql so put them in `''` (quotes) or user some other column names – Blu Mar 14 '14 at 05:39
  • You appear to be open to [SQL Injection](http://security.stackexchange.com/questions/tagged/sql-injection?sort=votes&pageSize=15). If you don't want your database to get owned, you need to use parameterized queries for this. – Clockwork-Muse Mar 14 '14 at 05:44

5 Answers5

3

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')
Trent
  • 2,909
  • 1
  • 31
  • 46
  • Make sure you accept the answer that gave your solution. Points make the world go round :) – Trent Mar 14 '14 at 05:44
1
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')"
Jalpa
  • 29
  • 4
0

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

Community
  • 1
  • 1
Neels
  • 2,547
  • 6
  • 33
  • 40
  • mysql uses backticks, not double quotes unless certain flags are turned on (not the default), to delimit reserved words – Bohemian Mar 14 '14 at 05:40
  • Oh really!! You can use double quotes if ANSI SQL mode is enabled! See the post whose link I posted. And I have been doing that for quite a while now. – Neels Mar 14 '14 at 05:43
0

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')"
0

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')
The Hungry Dictator
  • 3,444
  • 5
  • 37
  • 53