2012-12-22 70 views
0

我在if语句后面有多个命令的某些PHP代码时遇到问题。我已经终止与分号然而PHP引发以下错误每个命令:这个片段的if语句抛出错误中的多个命令

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依然相当陌生任何帮助将不胜感激。

回答

1

你错过了句号加入字符串:

所以

print 'alert("'$img_id' is already in '$type'")'; 

成为

print 'alert("'.$img_id.' is already in '.$type.'")'; 
+0

我知道我失去了一些东西简单。非常感谢你!我想我需要降低这台显示器的分辨率:/ –