|
-
Jun 15th, 2008, 09:45 PM
#1
Thread Starter
Frenzied Member
[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.
-
Jun 15th, 2008, 10:26 PM
#2
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']}' ) ";
-
Jun 16th, 2008, 06:44 PM
#3
Thread Starter
Frenzied Member
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
-
Jun 16th, 2008, 07:14 PM
#4
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.
-
Jun 16th, 2008, 09:15 PM
#5
Thread Starter
Frenzied Member
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.
-
Jun 16th, 2008, 09:21 PM
#6
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']}' ) ";
-
Jun 16th, 2008, 09:36 PM
#7
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|