我想在 if 条件下使用 php 重定向到不同的页面。(不是 javascript)我尝试作为示例 here .但不幸的是,它对我不起作用。 :/这是我的代码:
<html>
<body>
<?php
$time_type = $_POST['time_type'];
$driver_type = $_POST['driver_type'];
if (strcmp($time_type, "Arrival") && strcmp($driver_type, "Customer") )
{
header('location: http://localhost:8080/Project/Enter_Details.html');
exit();
}
?>
</body>
</html>
此 php 链接到下面的 html 页面。
<html>
<title> Shopping Complex</title>
<body>
<form name = "Type" action = "Type.php" method = "POST">
<fieldset>
<table>
<p>
<tr>
<td><input type = "radio"
name = "time_type" value = "Arrival">Arrival</input>
<input type = "radio"
name = "time_type" value = "Departure">Departure</input>
</td>
</tr>
<tr>
<td><input type = "radio"
name = "driver_type" value = "Staff">Staff</input>
<input type = "radio"
name = "driver_type" value = "Customer">Customer</input>
</td>
</tr>
</p>
<p>
<tr>
<td><input type = "submit"
value = "Go" id = "buttonId"></input>
</td>
</tr>
</p>
</table>
</fieldset>
</from>
</body>
</html>
请帮我解决这个问题......
最佳答案
您在发送 header (PHP 标签)之前发送数据(HTML 标签)
为了使其正常工作,请将 PHP 代码置于文档中的第一位,而不是任何 HTML。所以改变这个(也修复了上面提到的 $driver_type 和下面缺少分号的错误):
<html>
<body>
<?php
$time_type = $_POST['time_type'];
$driver_type = $_POST['driver_type'];
if (strcmp($time_type, "Arrival") && strcmp($driver_type, "Customer") )
{
header('location: http://localhost:8080/Project/Enter_Details.html');
die;
}
?>
</body>
</html>
仅此而已:
<?php
$time_type = $_POST['time_type'];
$driver_type = $_POST['driver_type'];
if (strcmp($time_type, "Arrival") && strcmp($driver_type, "Customer") )
{
header('location: http://localhost:8080/Project/Enter_Details.html');
die;
}
?>
关于PHP - 使用 if 条件重定向到不同的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25833723/