PHP Parse Error

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
i keep getting this error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kbjr/public_html/tays_sis/contact/process.php on line 22

this is the line in question (line 22):
PHP:
$msg = "Name: $_REQUEST['name']\nEmail: $_REQUEST['email']\nPurpose: $purpose\n\nMessage:\n$_REQUEST['message']";

please help, tell me if you need more info.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
one sec...I'm working on it...will edit result in soon :p
 
Last edited:

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
ok, here are the first 22 lines in the script:
PHP:
<?php

$sendtoAddress = "yourname@yourdomain.com";
$subject = "Message From Website";
$headerFrom = "messaging@yourdomain.com";    # set to "user defined" to display the address given in the form.

##################################################################################
##########    This page contains the processing data for the        ##########
##########    contact system. DO NOT MODIFY BEYOND THIS POINT.    ##########
##################################################################################

if ( $headerFrom == "user defined" ){
    $headerFrom = $_REQUEST['email'] ;
}

function sendMessage($sendtoAddress,$headerFrom){
    if ( $_REQUEST['purpose'] == "other" ){
        $purpose = $_REQUEST['other'] ;
    }else{
        $purpose = $_REQUEST['purpose'] ;
    }
    $msg = "Name: $_REQUEST['name']\nEmail: $_REQUEST['email']\nPurpose: $purpose\n\nMessage:\n$_REQUEST['message']";
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
With the simple syntax for variable interpolation in double-quotes, you don't delimit array indices with quotes:
Code:
$msg = "Name: $_REQUEST[name]\n[...]"

Generally speaking, when the parser complains about an "unexpected T_", (the T_ prefix denotes a token) in a case like this, I'd start looking for an extraneous or missing character.

You should read up on variable parsing in the strings section of the PHP manual.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
One more edit ><

Make sure the variables are set before using them. I get this error if the variable is undefined.
Edit:
I'm still wrong...It looks like indexes are the problem. If you replace $_REQUEST[...] with any other variable, it works, it's just the associative index. $_REQUEST[0] works, $name works, just not $_REQUEST['name']

from php.net:
Code:
<?php
// These examples are specific to using arrays inside of strings.
// When outside of a string, always quote array string keys and do not use
// {braces}.

// Show all errors
error_reporting(E_ALL);

$fruits = array('strawberry' => 'red', 'banana' => 'yellow');

// Works, but note that this works differently outside a string
echo "A banana is $fruits[banana].";

// Works
echo "A banana is {$fruits['banana']}.";

// Works, but PHP looks for a constant named banana first, as described below.
echo "A banana is {$fruits[banana]}.";

// Won't work, use braces.  This results in a parse error.
echo "A banana is $fruits['banana'].";

// Works
echo "A banana is " . $fruits['banana'] . ".";

// Works
echo "This square is $square->width meters broad.";

// Won't work. For a solution, see the complex syntax.
echo "This square is $square->width00 centimeters broad.";
?>
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Actually, "$y/n" is perfectly valid and $y will interpolate properly. The parser is greedy but won't take characters that form an invalid identifier, like '/'. In other cases where a variable name is immediately followed by valid identifier characters ($foo="foo"; "$foobar";), use brackets to delimit the variable name ($foo="foo"; "${foo}bar";) or use complex syntax:
Code:
[FONT="Courier New"]$foo=new Thing('bar', 'bam');
"I made a {$foo->name()} for {$_REQUEST['name']}.";[/FONT]

Edit:
If you're wondering why I mention "$y/n", it's because it was in an earlier version of the above post.
 
Last edited:
Top