Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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的简单登录表单_Php_Html_Login - Fatal编程技术网

使用php的简单登录表单

使用php的简单登录表单,php,html,login,Php,Html,Login,我正在尝试写一个简单的登录表单。 但无论我输入什么密码,我总是被引导到同一个页面。 我是php新手,请原谅我的简单问题 <?php if(isset($_POST['password'])) { if($_POST['password'] == 'admin') { header ( 'Location: home.html '); } else { echo "Wrong Pa

我正在尝试写一个简单的登录表单。 但无论我输入什么密码,我总是被引导到同一个页面。 我是php新手,请原谅我的简单问题

    <?php
    if(isset($_POST['password'])) {
        if($_POST['password'] == 'admin') {
            header ( 'Location: home.html ');
        }
        else {
            echo "Wrong Password";
            exit ;  
        }
    }
    ?>
    <html>
    <form action="index.php" method ="POST">
        Please Enter the Password:
        </br>
        <input type= "password" name= "password" />
        <input type = "submit" value = "Go!"  />
    </form>
</html>

请输入密码:

尝试更改

metod ="POST"
致:

  • 它不是
    方法
    ,它的
    方法
  • 表单中需要一个enctype,通常可以使用
    enctype=“multipart/form data”
  • 请尝试以下代码:-

    <?php
        if(isset($_POST['submit'])) 
        {
           if($_POST['password'] == 'admin') 
           {
               header ( 'Location: home.html ');
           }
           else 
           {
               echo "Wrong Password";
               exit ;  
           }
        }
     ?>
     <html>
     <form action="index.php" method ="POST">
      Please Enter the Password:
      </br>
     <input type= "password" name= "password" />
     <input type = "submit" name="submit" value = "Go!"  />
    
     </form>
    
    
    请输入密码:
    
    
    泰尔,这是密码。在行动中使用#

    if($\u POST['password']=='admin'){
    标题('Location:home.html');
    }
    否则{
    回显“密码错误”;
    出口
    }
    }
    ?>
    请输入密码:
    
    试试这个

    if(isset($_POST['submit'])) {
            if($_POST['password'] == 'admin') {
                header ('Location:process.php');
            }
            else {
                echo "Wrong Password";
                exit ;
            }
        }
        ?>
        <form action="enclosedHTMLtag.php" method="post">
            Please Enter the Password:
            </br>
            <input type="password" name="password" />
            <input type="submit" value="Go!" name="submit" />
        </form>
    
    if(isset($\u POST['submit'])){
    如果($_POST['password']=='admin'){
    标题('Location:process.php');
    }
    否则{
    回显“密码错误”;
    出口
    }
    }
    ?>
    请输入密码:
    
    我在
    enclosedHTMLtag.php
    编写了这段代码,我正在
    enclosedHTMLtag.php
    提交这张表格,如果你想在任何文件中提交这张表格,请将这张表格更改为
    action=“enclosedHTMLtag.php”


    更简单的是,如果您想在同一页提交表单,请使用此
    +1,用于鹰眼;)谢谢!没注意到!:)检查我的@user2727841答案…为什么“?>”在你代码的末尾?我想他只是忘了删除它。^^@Ashish是的,如果表单操作php代码在同一页面中,则应写为“表单操作=”“method=“post”“>。您的代码没有问题。如果您的编码文件名为
    index.php
    ,与您的
    操作
    相同,那么它应该可以工作,就像我的测试一样。如有疑问,请使用
    action=“
    而不是
    action=“index.php”
    <?php
    if(isset($_POST['password'])) {
        if($_POST['password'] == 'admin') {
            header ( 'Location: home.html ');
        }
        else {
            echo "Wrong Password";
            exit ;  
        }
    }
    ?>
    <html>
    <form action="<?echo $PHP_SELF;?>"  method ="POST">
        Please Enter the Password:
        </br>
        <input type= "password" name= "password" />
        <input type = "submit" value = "Go!"  />
    </form>
    
           if($_POST['password'] == 'admin') {
               header ( 'Location: home.html ');
           }
           else {
               echo "Wrong Password";
               exit ;
           }
       }
       ?>
       <html>
       <form action="#" method="post">
           Please Enter the Password:
           </br>
           <input type= "password" name= "password" />
           <input type = "submit" value = "Go!"  name="submit" />
       </form>
    </html>
    
    if(isset($_POST['submit'])) {
            if($_POST['password'] == 'admin') {
                header ('Location:process.php');
            }
            else {
                echo "Wrong Password";
                exit ;
            }
        }
        ?>
        <form action="enclosedHTMLtag.php" method="post">
            Please Enter the Password:
            </br>
            <input type="password" name="password" />
            <input type="submit" value="Go!" name="submit" />
        </form>