Results 1 to 7 of 7

Thread: [RESOLVED] Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Resolved [RESOLVED] Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    Hi all. i get the following error . could any one help me fixing it.Thanks


    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in

    error pointing to :
    PHP Code:
                        $query "INSERT INTO music (`ID`,`friendID`,`friendPicture`,`friendName`) VALUES ('$ID',' . $friend['id'] . ',' . $friend['picture'] . ',' . $friend['name'] . ')"



    PHP Code:
    ....
    ....

    foreach (
    $friends as $friend)
        {

            
    //here you can write to mysql


            
    if ($_POST['format'] == 'table')
                    {
                
    fwrite($handle'
                <tr>
                    <td><a href="http://www.somsite.com/id=' 
    $friend['id'] . '">' $friend['id'] . '</a></td>' . (!empty($_POST['photos']) ? '
                    <td><img src="' 
    $friend['picture'] . '" alt="" /></td>' '') . '
                    <td>' 
    $friend['name'] . '</td>
                </tr>'
    );


             

                        
    $query "INSERT INTO music (`ID`,`friendID`,`friendPicture`,`friendName`) VALUES ('$ID',' . $friend['id'] . ',' . $friend['picture'] . ',' . $friend['name'] . ')";
                        
    $fp fopen("videos.txt""w");
                        
    fwrite($fp$query);
                        
    fclose($fp);      
                        
    $result mysql_query$query );
                     }
            else
            
                
    fwrite($handle'<li>
                    <a href="http://www.somsite.com/id=' 
    $friend['id'] . '">
                        ' 
    . (!empty($_POST['photos']) ? '<img src="' $friend['picture'] . '" alt="" /><br />
                        ' 
    '') . $friend['name'] . '
                    </a><br />
                </li>'
    );
        } 
    Last edited by tony007; Jun 15th, 2008 at 10:08 PM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    You've got quotes and dots where there shouldn't be.
    Although it's not always necessary, I recommend consistently using braces around embedded variables. This makes the string far easier to read.

    PHP Code:
    $query "
      INSERT INTO music (
        ID,
        friendID,
        friendPicture,
        friendName
      )
      VALUES (
        '
    {$ID}',
        '
    {$friend['id']}',
        '
    {$friend['picture']}',
        '
    {$friend['name']}'
      )
    "


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    Thanks it worked well but only problem i get so many of the following notices

    Notice: Undefined variable: ID in

    and pointing to my insert statement. The data gets inserted to mysql but i get this strange notices. Could help me how to avoid them ?Thanks

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    That is an indication that you have tried to read a variable that you never created. Where are the variables within your insert statement coming from. You can use the isset() construct to check for the existance of one or more variables before using them.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    Thanks for your reply.The $ID variable is auto incremented inside mysql . So it doesn't get any value from with in script. It is generated for each record inserted inside mysql table. The other 2 varibles are coming from an array.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    If ID column is auto increment then just omit it from the insert query.

    PHP Code:
    $query "
      INSERT INTO music (
        friendID,
        friendPicture,
        friendName
      )
      VALUES (
        '
    {$friend['id']}',
        '
    {$friend['picture']}',
        '
    {$friend['name']}'
      )
    "


  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    Thanks penagate that fixed the problem. Now it works without any error :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width