0

I am getting this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

for this query:

$insert = mysql_query("INSERT INTO bookings (product_code, email, delivery, del_date, col_date, booking_date, event_type, quantity, cost) VALUES (".$_SESSION["booking"].", ".$_SESSION["logged_in"].", ".$_SESSION["delivery"].", ".$_SESSION["del_date"]", ".$_SESSION["col_date"].", ".$current_date.", ".$_SESSION["event_type"].", ".$_SESSION["quantity"].", ".$_SESSION["price"].")");

And I can't work out what is causing it, I have tried everything I can think of, but I am not very experienced with MySQL queries.

EDIT: I have solved this now, and another error which is now corrected is I missed out the ' around the session variables, for example:

VALUES ("'".$_SESSION["variable"]."', '".$_SESSION["variable2"]."'")
RJE95
  • 45
  • 4

2 Answers2

2

There is missing dot in your string.

ivery"].", ".$_SESSION["del_date"]", ".$_SESSION["col_date"]."
                                  ^ here
René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • Ah, thank you very much! I hadn't spotted that, I thought maybe the way I was doing the whole thing was wrong – RJE95 Apr 17 '14 at 15:47
  • 2
    @RJE95: _I thought maybe the way I was doing the whole thing was wrong_ - It is, `mysql_*` functions are [**deprecated**](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – The Blue Dog Apr 17 '14 at 15:50
  • @TheBlueDog I am aware that mysql_* functions are out of date, but this won't actually be used live, it is for an exam in which I have been asked to use mysql_* rather than mysqli_*. But thanks for pointing it out :) – RJE95 Apr 18 '14 at 13:43
  • @RJE95: Whether it's live or not is largely irrelevant, particularly if you are in the learning phase. Practice good coding now and don't get into the nasty habit of 'fixing it later', it'll make you a better programmer in the long run. Just for shits and giggles, explain to your tutor why being told to use mysql_* functions is a really bad idea and that he should be fired for insisting on it :) – The Blue Dog Apr 18 '14 at 15:16
  • @TheBlueDog In the long run I don't plan to be a programmer, but some of my class mates do. This is only an A-level course so hopefully they will be taught correctly at uni if they continued. And trust me, this is not outdated compared to other things we are being taught on this course :p – RJE95 Apr 18 '14 at 15:27
  • @RJE95: Ha ha! Seeing some of the questions on here, I quite believe it. Good luck with whatever you decide to do in the future! – The Blue Dog Apr 18 '14 at 15:30
1

Copy code below it should work; you skipped a dot on your query

$insert = mysql_query("INSERT INTO bookings (product_code, email, delivery, del_date, col_date, booking_date, event_type, quantity, cost) VALUES (".$_SESSION["booking"].", ".$_SESSION["logged_in"].", ".$_SESSION["delivery"].", ".$_SESSION["del_date"].", ".$_SESSION["col_date"].", ".$current_date.", ".$_SESSION["event_type"].", ".$_SESSION["quantity"].", ".$_SESSION["price"].")");
neubert
  • 15,947
  • 24
  • 120
  • 212