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

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

문제

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"]."'")
도움이 되었습니까?

해결책

There is missing dot in your string.

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

다른 팁

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"].")");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top