首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >if语句中的多个命令引发错误

if语句中的多个命令引发错误
EN

Stack Overflow用户
提问于 2012-12-22 22:35:00
回答 1查看 92关注 0票数 0

我在一些PHP代码中遇到了问题,在if语句后面有多个命令。我用分号终止了每个命令,但是php抛出了以下错误:

代码语言:javascript
复制
PHP Parse error:  syntax error, unexpected T_VARIABLE in /test/process.php on line 18

引用此代码段的第4行:

代码语言:javascript
复制
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的新手。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-22 22:37:37

您缺少句号来连接字符串:

所以

代码语言:javascript
复制
print 'alert("'$img_id' is already in '$type'")';

变成了

代码语言:javascript
复制
print 'alert("'.$img_id.' is already in '.$type.'")';
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14003675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档