[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
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>');
}
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']}'
)
";
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
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.
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.
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']}'
)
";
Re: Help fixing :parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE
Thanks penagate that fixed the problem. Now it works without any error :-)