首页 > 解决方案 > 如果 all = 1,则检查 php 中的 html 输入,重定向

问题描述

所以我对此很陌生,我似乎无法弄清楚为什么这不起作用

如果所有文本框都包含数字 1,我希望 php 文件重定向我。

到目前为止,这是我的代码:

html file:
<!DOCTYPE HTML>
    <html>
        <head>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link rel="stylesheet" type="text/css" href="styleIndex.css">
        </head>
        <body>

            <div class="middle">
                <h1>ENTER CODE</h1>
            </div>

            <div class="Code">
                <form action=action.php method="post">
                    <input type="text" placeholder="0" maxlength="1" name="nm1" required>
                    <input type="text" placeholder="0" maxlength="1" name="nm2" required>
                    <input type="text" placeholder="0" maxlength="1" name="nm3" required>
                    <input type="text" placeholder="0" maxlength="1" name="nm4" required>
                    <input type="text" placeholder="0" maxlength="1" name="nm5" required>
                    <input type="submit" name="submit" hidden>
                </form>
            </div>
       </body>
  </html>

action.php 文件:

<?php 
if (isset($_POST['nm1']) && ($_POST['nm2'] && ($_POST['nm3'] && ($_POST['nm4'] && ($_POST['nm5'] ='1') {
    header("Location: http://www.kr0kk0.tk/mainpage.php")
}
?>

标签: phphtml

解决方案


如果其中有值,您所做的将返回 true,但是它不会检查它包含的值。你应该这样做:

<?php 
    if(isset($_POST['submit']) {
        if(($_POST['nm1'] == 1) && ($_POST['nm2'] == 1) && ($_POST['nm3'] == 1) && ($_POST['nm4'] == 1) && ($_POST['nm5'] == 1)) {
            header("Location: http://www.kr0kk0.tk/mainpage.php");
        }
    }
?>

推荐阅读