我在if语句后遇到一些带有多个命令的PHP代码时出现问题。我用分号终止了每个命令但是php抛出了以下错误:
PHP Parse error: syntax error, unexpected T_VARIABLE in /test/process.php on line 18
引用此代码段的第4行:
if (mysql_num_rows($duperaw) > 0)
{
print '<script type="text/javascript">';
print 'alert("'$img_id' is already in '$type'")';
print '</script>';
header("location: process.php?img_id=$img_id");
}
else
{
mysql_query("INSERT INTO $type (data) VALUES('$data')");
print '<script type="text/javascript">';
print 'alert("'$img_id' successfully added to '$type'")';
print '</script>';
}
代码在每个{}中都有一行正常工作但是我认为{}的功能是允许在每个if语句中运行多个命令。我可能只是忽略一些非常简单的东西,因为我仍然是相当新的PHP。任何帮助将不胜感激。
答案 0 :(得分:1)
你错过了加入字符串的句号:
所以
print 'alert("'$img_id' is already in '$type'")';
变为
print 'alert("'.$img_id.' is already in '.$type.'")';