-1

我的 php 脚本根据按下的提交按钮指向一个 url。但是,当我运行测试时,我收到一条错误消息,指出第 4 行包含意外的“:”,但我的第 4 行是带有 url 的标题脚本?

我很困惑,因为我还有其他类似的脚本,但他们没有给我那个错误。谁能告诉我我错过了什么,可能很简单,我之前被抓到很简单。

<?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.....
?>
4

4 回答 4

4
于 2012-09-05T20:33:15.290 回答
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 ; )

于 2012-09-05T20:33:54.507 回答
0

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']));
}

?>
于 2012-09-05T20:43:12.083 回答
0

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']]);
于 2012-09-05T20:53:09.743 回答