我在一些PHP代码中遇到了问题,在if语句后面有多个命令。我用分号终止了每个命令,但是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的新手。任何帮助都将不胜感激。
发布于 2012-12-22 22:37:37
您缺少句号来连接字符串:
所以
print 'alert("'$img_id' is already in '$type'")';变成了
print 'alert("'.$img_id.' is already in '.$type.'")';https://stackoverflow.com/questions/14003675
复制相似问题