mysq_error()

Problems INSERTing into table in my database...

Page 1 of 1

2 Replies - 949 Views - Last Post: 18 October 2009 - 03:53 PM

#1 fredontime  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 09

mysq_error()

Posted 18 October 2009 - 09:24 AM

Hello i am am newbie and i am having problem storing data into the table i created in my database .


Here is the SQL statement below :

else
{
$sql = "INSERT INTO airbookings (fname,lname,from,to,departure,type,class,adults,kids,infants,srequest,date,time)
VALUES('$nm','$lm','$frm','$to','$dpt','$tp','$cls','$adt','$kd','$inft','$srqst','$date','$time')";
$process=mysql_query($sql) or die("Query failed : ".mysql_error());
$message="Registration successful";
include("Booking.php");
exit();
}

Each time i try to INSERT i get this mysql_error MSG :

Query failed : 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,to,departure,type,class,adults,kids,infants,srequest,date,time) VALUES('Dh' at line 1

Please what can i do ?

Is This A Good Question/Topic? 0
  • +

Replies To: mysq_error()

#2 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: mysq_error()

Posted 18 October 2009 - 12:41 PM

Hi,
your syntax looks OK, but maybe there is something breaking out the sql string.
and it's maybe the $lm (according to the error message).
so, make sure you're passing allowable values
Was This Post Helpful? 0
  • +
  • -

#3 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: mysq_error()

Posted 18 October 2009 - 03:53 PM

View Postfredontime, on 18 Oct, 2009 - 10:24 AM, said:

$sql = "INSERT INTO airbookings (fname,lname,from,to,departure,type,class,adults,kids,infants,srequest,date,time)

Your problem is in your field names. Both "from" and "to" are reserved words in SQL. You need to enclose them in back quotes so they won't be treated as such, like this:
INSERT INTO airbookings (fname,lname,`from`,`to`, ...

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1