首页 > 解决方案 > 来自一页的两次重定向

问题描述

如何通过单击两个不同的按钮从一个 html 页面重定向到两个不同的 php 页面?我有两个按钮,btn1 和 btn2

*如果我点击 btn1,html 页面页面应该重定向到page1.php表单值。

*以同样的方式,如果我点击 btn2,html 页面页面应该重定向到page2.php与表单值。

<form action = "check.php" method = "post">
    <div align = "center">
        <table>
            <thead><h2>LOGIN FORM<h2></thead>
            <tr>
                <td><h4>Username</h4></td>
                <td><input type = "text" name = "username"></td>
            </tr>

            <tr>
                <td><h4>Password</h4></td>
                <td><input type = "password" name = "password"></td>
            </tr>

            <tr>
                <td><button name = "register">Sign up</button></td>
                <td><button name = "submit">Login</button></td>
            </tr>
        </table>
    </div>
</form>

在这里,如果我点击登录,我必须转到 check.php,如果我点击注册,它应该被重定向到 sample.php。

但是在上面的代码中,我只能重定向到一个 php 文件。

如何将注册按钮重定向到另一个 php 文件?

标签: php

解决方案


相反,您可以重定向到一个页面并添加两个功能:

由于您已经将登录按钮命名为提交,在php文件中检查是否设置了提交,如果是,则添加登录操作。如果不是,则在else部分添加sign up的操作。


推荐阅读