簡體   English   中英

單擊html中的按鈕元素后提交不起作用

[英]Submit not working after clicking an button element in html

我是Web開發的新手,所以請理解我。

單擊按鈕以HTML格式提交PHP后,它只會重新加載我的login.html

如果用戶的憑據正確,有人可以幫助我將登錄頁面重定向到索引頁面。

這是代碼:

HTML:

 <?php include('php/pLogin.php'); ?>
 <form action="" method="POST">
                <div class="login-form-head">
                    <h4>Sign In</h4>
                    <p>Hello there, Sign in and start managing your Admin 
                    Template</p>
                </div>
                <div class="login-form-body">
                    <div class="form-gp">
                        <label for="txtUser">Email address</label>
                        <input type="text" id="txtUser" name="txtUser">
                        <i class="ti-email"></i>
                    </div>
                    <div class="form-gp">
                        <label for="txtPass">Password</label>
                        <input type="password" id="txtPass" name="txtPass">
                        <i class="ti-lock"></i>
                    </div>
                    <div class="row mb-4 rmber-area">
                        <div class="col-6">
                            <div class="custom-control custom-checkbox mr-sm-2">
                                <input type="checkbox" class="custom-control-input" id="customControlAutosizing">
                                <label class="custom-control-label" for="customControlAutosizing">Remember Me</label>
                            </div>
                        </div>
                        <div class="col-6 text-right">
                            <a href="#">Forgot Password?</a>
                        </div>
                    </div>
                    <div class="submit-btn-area">
                        <button id="btnLogin" type="submit" value="Submit">Login <i class="ti-arrow-right"></i></button>
                    </div>
                    <div class="form-footer text-center mt-5">
                        <p class="text-muted">Don't have an account? <a href="register.html">Sign up</a></p>
                    </div>
                </div>
            </form>

PHP:Login.php

<?php
    include("pConfig.php");
    session_start();
    if($_POST['txtUser'] != '' && $_POST['txtPass'] !='') {
        $error = '';
        // username and password sent from form 
        echo $myusername = mysqli_real_escape_string($db,$_POST['txtUser']);
        echo $mypassword = mysqli_real_escape_string($db,$_POST['txtPass']); 
        //$sql = "SELECT user_id  FROM user WHERE username = '$myusername' and password = '$mypassword'";
        $sql = "SELECT * FROM userinfo WHERE (UserName = '$myusername' OR Email = '$myusername' ) and Password = '$mypassword'";
        $result = mysqli_query($db,$sql);
        $rows = mysqli_fetch_array($result);
        $count = mysqli_num_rows($result);
        // If result matched $myusername and $mypassword, table row must be 1 row
        if($count == 1) {
            //prevent session fixation attack
            session_regenerate_id();
            $_SESSION['login_user'] = $myusername; 
            header("Location: index.html");
        } else {
            $error = 'Incorrect UserName Or Password, Please Check your Credentials';
        }
    }
?>

Config.php

<?php
   define('DB_SERVER', 'localhost');
   define('DB_USERNAME', 'root');
   define('DB_PASSWORD', '');
   define('DB_DATABASE', 'ci');
   $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

這是因為表單中的action屬性為空

action=""

您需要將其指向您的php文件,如下所示:

action="/path/to/your/file.php"

如果action屬性為空,它將指向/刷新包含表單的文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM