Parse error: syntax error, unexpected '}' but can not find another [closed]

心不动则不痛 提交于 2019-12-03 01:04:51

问题


Ok so I created a form that has one field but multiple submit buttons. Have the form correct, no problem there. Have an issue writing the php code to perform an action depending on which button is pressed. Keep getting a parse and syntax error. I have tried different variations of using the if/else statements as well as isset. Still no luck. AND I don't see any extra } that Im aware of.

    <?php
if($_REQUEST['Gift'] == "Dish1")
{
  header("Location: url1".urlencode($_POST['uid']))
}

else if($_REQUEST['Gift'] == "Dish2")
{
  header("Location: url2".urlencode($_POST['uid']))
}

else if($_REQUEST['Gift'] == "Dish3")
{
  header("Location: url3".urlencode($_POST['uid']))

}

.....etc ?>

It says the error is online 5.... not sure how they parse their lines as the actual url addresses are quite long themselves and none contain }


回答1:


You are missing a ; at the end of your header statements.

The } is not expected because a ; (or something else allowed there) is required first.




回答2:


You don't have semicolons. Every statement in PHP must have ';' at the end.




回答3:


You need to pop ; after statements:

header("Location: url1".urlencode($_POST['uid']));


来源:https://stackoverflow.com/questions/12261161/parse-error-syntax-error-unexpected-but-can-not-find-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!