Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-使用if条件重定向到不同的页面_Php_Redirect_If Statement_Web_Conditional - Fatal编程技术网

PHP-使用if条件重定向到不同的页面

PHP-使用if条件重定向到不同的页面,php,redirect,if-statement,web,conditional,Php,Redirect,If Statement,Web,Conditional,我想使用php(不是javascript)重定向到if条件下的不同页面,我试着以此为例。但不幸的是,它对我不起作用。:/这是我的密码: <html> <body> <?php $time_type = $_POST['time_type']; $driver_type = $_POST['driver_type']; if (strcmp($time_type, "Ar

我想使用php(不是javascript)重定向到if条件下的不同页面,我试着以此为例。但不幸的是,它对我不起作用。:/这是我的密码:

<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>

购物中心

进站
离开
工作人员
顾客

请帮我解决这个问题……

在发送标题(PHP标记)之前,您正在发送数据(HTML标记)

为了让它工作,让PHP代码成为文档中的第一件事,而不是任何HTML。因此,请对此进行更改(还修复了上面提到的$driver_类型和下面缺少分号的错误):


为此:

<?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;
    }
?>

如果我没记错的话,你忘了给分号
到您的
标题()
code

1。检查
Type.PHP中的PHP代码
如果要输出标题(或使用输出缓冲捕获标题),请避免执行任何HTML输出,特别是在这种情况下,这是不必要的

2.检查您的HTML代码: 这不是有效的HTML代码:

<input type = "radio" name = "time_type" value = "Arrival">Arrival</input>
到达
有效版本:

<input type = "radio" name = "time_type" value ="Arrival">


您的程序中有一个输入错误
strcmp($diver\u type,“Customer”)
更改为$driver\u type。还有echo$\u POST变量。它是
strcmp($driver\u type,“Customer”)
而不是
strcmp($driver\u type,“Customer”)
。接下来,您将打开
html
body
标记,这是输出。。。不要打开那些。@Dorvalla是的。谢谢我已经更正了。只是提示一下,strcmp是一个二进制比较,所以如果evaluate等于,它将返回0,并将转换为false。否则,如果字符串不同,它将返回1(大于)或-1(小于)。这两种情况都将成为事实。
<input type = "radio" name = "time_type" value ="Arrival">