Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE


[SOLVED] Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

Reply
  #1 (permalink)  
Old 06-15-08, 09:48 PM
method method is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] 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


Quote:
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 method; 06-15-08 at 10:07 PM.
Reply With Quote
  #2 (permalink)  
Old 06-15-08, 10:25 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Change to:

PHP Code:

$query "INSERT INTO music (`ID`,`friendID`,`friendPicture`,`friendName`) VALUES ('$ID','{$friend['id']}','{$friend['picture']}','{$friend['name']}')"
Reply With Quote
  #3 (permalink)  
Old 06-16-08, 06:45 PM
method method is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #4 (permalink)  
Old 06-16-08, 08:36 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
ID is probably an autoincrement identifier, and thus shoud not be set.

Try removing it from the INSERT statement to see if it still works.
Reply With Quote
  #5 (permalink)  
Old 06-16-08, 09:07 PM
method method is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
well i need the insert statement and if i remove it i will not get error !!
Is there away to keep the insert and not to get the error. it is just annyoing to get so many of such error
Reply With Quote
  #6 (permalink)  
Old 06-16-08, 11:52 PM
method method is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
problem got solved by removing ID from insert statment :-)Thanks for all for helping me .
Reply With Quote
  #7 (permalink)  
Old 06-17-08, 01:38 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
I'm fairly sure that the undefined variable notice had nothing to do with the database, it was because you had not initialised the $ID variable before the query line
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #8 (permalink)  
Old 06-17-08, 06:30 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
The error message was issued because $ID was not initialized.

Many times, database ids are assigned by the database by setting the field up as an autoincrement field, in which case, assigning them is will also cause an error.

In order to be sure removing $ID from the INSERT command was the correct solution (and to avoid future problems) - you should check to see if the ID is an autoincrement field, and if it is supposed to be unique.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: Very small script :) please help agrublev PHP 6 09-07-06 11:24 PM
Parse error: parse error, unexpected '\"' unlisted80 PHP 5 07-19-06 01:35 AM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING cveselka PHP 1 04-25-06 01:51 PM
Parse error: parse error, unexpected $ in... keefermedia PHP 4 04-23-06 11:21 AM
Parse error: parse error, unexpected T_VARIABLE aussietogo PHP 4 08-16-05 08:14 PM


All times are GMT -5. The time now is 07:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.