+ Reply to Thread
Results 1 to 7 of 7

Thread: PHP Parse Error

  1. #1
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    PHP Parse Error

    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 Code:
    $msg "Name: $_REQUEST['name']\nEmail: $_REQUEST['email']\nPurpose: $purpose\n\nMessage:\n$_REQUEST['message']"
    please help, tell me if you need more info.

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP Parse Error

    one sec...I'm working on it...will edit result in soon :P
    Last edited by garrettroyce; 04-08-2009 at 08:37 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Re: PHP Parse Error

    ok, here are the first 22 lines in the script:
    PHP Code:
    <?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']";

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP Parse Error

    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.

  5. #5
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP Parse Error

    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 by garrettroyce; 04-08-2009 at 08:53 PM. Reason: Automerged Doublepost
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP Parse Error

    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:
    $foo=new Thing('bar', 'bam');
    "I made a {$foo->name()} for {$_REQUEST['name']}.";
    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 by misson; 04-08-2009 at 09:03 PM.

  7. #7
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Re: PHP Parse Error

    thank you for the help, it works now.

+ Reply to Thread

Similar Threads

  1. Parse error: syntax error (PHP)
    By port5900 in forum Programming Help
    Replies: 2
    Last Post: 11-30-2008, 03:47 PM
  2. Wordpress PHP Error
    By wolf693 in forum Free Hosting
    Replies: 2
    Last Post: 04-13-2008, 01:59 PM
  3. Fantastico Parse error line 31?????
    By Dazz in forum Free Hosting
    Replies: 2
    Last Post: 09-03-2007, 12:37 AM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers