Page 1 of 1

PHP Parse error: unexpected T_VARIABLE

Posted: Tue Feb 10, 2009 5:36 pm
by OU_Student
Hello,

Can anyone please help me with this error: [10-Feb-2009 13:26:08] PHP Parse error: syntax error, unexpected T_VARIABLE.

My code is below:
############
$sql = "INSERT INTO `database_test`.`Users` (`f_name`,`l_name`,`address`,`address_two`,`city`,`state`,`zip`,`phone`,`email`,`user_name`,`password`) VALUES ('$_POST[fName]','$_POST[lName]','$_POST[addressOne]','$_POST[addressTwo]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[phone]','$_POST[email]','$_POST[userName]','$_POST[password]';";

Thanks!

Re: PHP Parse error: unexpected T_VARIABLE

Posted: Tue Feb 10, 2009 5:46 pm
by requinix
No errors there, except the missing ) at the end of the query.

Did you forget a semicolon on the line above?

Re: PHP Parse error: unexpected T_VARIABLE

Posted: Tue Feb 10, 2009 5:47 pm
by jayshields
Can't put array indices inside double quotes without enclosing them in curly braces. Must enclose string array indices with quotes. Missing closing bracket in query. Unnecessary semi-colon in query.

Re: PHP Parse error: unexpected T_VARIABLE

Posted: Tue Feb 10, 2009 5:54 pm
by OU_Student
Thank you, works now =)

Re: PHP Parse error: unexpected T_VARIABLE

Posted: Tue Feb 10, 2009 6:20 pm
by requinix
jayshields wrote:Can't put array indices inside double quotes without enclosing them in curly braces. Must enclose string array indices with quotes.
Umm, no.

Re: PHP Parse error: unexpected T_VARIABLE

Posted: Wed Feb 11, 2009 10:46 am
by jayshields
Huh?

That was two seperate statements I made, sorry.

To elaborate; I meant:

Can't put array indices inside double quotes without enclosing them in curly braces.

Code: Select all

$sql = "blah blah '$_POST['addressOne']'"; //wrong
$sql = "blah blah '{$_POST['addressOne']}'"; //right
Must enclose string array indices with quotes.

Code: Select all

$sql = "blah blah '{$_POST[addressOne]}'"; //wrong
$sql = "blah blah '{$_POST['addressOne']}'"; //right