Syntax error - unexpected “:” [closed]

强颜欢笑 提交于 2019-12-17 21:23:30

问题


My php script directs to a url depending on which submit button was pressed. However, when I run the test I'm getting an error saying line 4 contains an unexpected ":" but my line 4 is my header script with the url?

I'm confused because I have other scripts similar to this and they don't give me that error. Can anyone tell me what I'm missing, might be simple, I have been caught being simple before.

<?php
if ($_REQUEST['Dish1'] == 'Dish1')
{
header(“Location: http://blahblah”.urlencode($_POST[‘uid’]));
}
else if ($_REQUEST['Dish1'] == 'Dish2')
{
header(“Location: http://blahblah2”.urlencode($_POST[‘uid’]));
}
else if ($_REQUEST['Dish1'] == 'Dish3')
{
header(“Location: http://blahblah3”.urlencode($_POST[‘uid’]));
}
etc.....
?>

回答1:


You are using curly quotes.

Replace all the “ ” and ‘ ’ to " and ' respectively.




回答2:


You are using the wrong quotes... use "" instead of “”. Refer to Wikipedia, you must use typewriter quotes, not curly or inverted commas.

PD: Also PHP Parse error: syntax error, unexpected '.' on line 15 ; )




回答3:


Replace you code with following

<?php

if ($_REQUEST['Dish1'] == 'Dish1')
{
header("Location: http://blahblah.urlencode".($_POST['uid']));
}
else if ($_REQUEST['Dish1'] == 'Dish2')
{
header("Location: http://blahblah2".urlencode($_POST['uid']));
}
else if ($_REQUEST['Dish1'] == 'Dish3')
{
header("Location: http://blahblah3".urlencode($_POST['uid']));
}

?>



回答4:


Is it not much easier to write:

$lookup = array('Dish1' = > 'http://blba1', 'Dish2' = > 'http://blba2');

if( isset($lookup[$_REQUEST['Dish1']]))
  header("Location: " . $lookup[$_REQUEST['Dish1']]);


来源:https://stackoverflow.com/questions/12289278/syntax-error-unexpected

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