【发布时间】:2014-11-08 03:13:15
【问题描述】:
我想使用 php 在 if 条件下重定向到不同的页面。(不是 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>
请帮我解决这个问题......
【问题讨论】:
-
您的程序中有错字
strcmp($diver_type, "Customer")更改为$driver_type。同时回显 $_POST 变量。 -
它是
strcmp($driver_type, "Customer")而不是strcmp($diver_type, "Customer")。在此旁边,您打开html和body标签,这是输出...不要打开那些。 -
@Dorvalla 是的。谢谢.....我已经更正了。
-
提示一下,strcmp 是二进制比较,所以如果计算为相等,它将返回 0 并被强制转换为 false。否则,如果字符串不同,它将返回 1(大于)或 -1(小于)。这两种情况都将被强制转换为 true。
标签: php redirect if-statement web conditional