PHP Parse error: unexpected T_VARIABLE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OU_Student
Forum Newbie
Posts: 7
Joined: Tue Feb 10, 2009 5:30 pm

PHP Parse error: unexpected T_VARIABLE

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Parse error: unexpected T_VARIABLE

Post by requinix »

No errors there, except the missing ) at the end of the query.

Did you forget a semicolon on the line above?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: PHP Parse error: unexpected T_VARIABLE

Post 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.
OU_Student
Forum Newbie
Posts: 7
Joined: Tue Feb 10, 2009 5:30 pm

Re: PHP Parse error: unexpected T_VARIABLE

Post by OU_Student »

Thank you, works now =)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Parse error: unexpected T_VARIABLE

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: PHP Parse error: unexpected T_VARIABLE

Post 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
Post Reply