Unexpected T_CONSTANT_ENCAPSED_STRING in PHP when inserting $_SESSION variables with MySQL [closed]

StackOverflow https://stackoverflow.com/questions/23137614

Question

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"]."'")
Was it helpful?

Solution

There is missing dot in your string.

ivery"].", ".$_SESSION["del_date"]", ".$_SESSION["col_date"]."
                                  ^ here

OTHER TIPS

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"].")");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top