简体   繁体   English

HTML表单操作字段未执行

[英]Html form action field is not executed

This form is written to get login details from user & provide the details in the login page where the login.php file is executed. 编写此表单是为了获取用户的登录详细信息,并在执行login.php文件的登录页面中提供详细信息。

<div id="log_btn">
<section id="form_before_launch">
<p style="font-family: Arial, Helvetica, sans-serif;">LogIn</p>
<form action="login.php" id="form" method="POST" onsubmit="return false">
    <div>
        <div>
            **<!-- Fields of Login page -->**
            <input type="text" id="username" name="uname" placeholder="Username" required />
        </div>
        <div>
            <input type="password" id="password" name="pass" placeholder="password" required />
        </div>
        **<!-- Captcha is Displayed in id="ip" & users enters the captcha in id "op" on Submit login page is executed -->**
        <div>
            <input type="text" id="ip" name="ip" />
            <br>
            <input type="text" id="op" name="op" />
        </div>
        <br><br><br>
        <div id="btn">
            <input type="submit" id="submit" value="Log In" />
        </div>
</form>
</div>

The login.php part if you need to see test the form is really sending the input result to the login.php 如果您需要查看测试表单,则login.php部分实际上是将输入结果发送到login.php

    <?php

$servername = "localhost";
$username   = "root";
$password   = "";
$dbname     = "Train";
$conn       = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $ip_uid  = $_POST['uname'];
    $ip_pass = $_POST['pass'];
    $ip      = $_POST['ip'];
    $op      = $_POST['op'];
}
function input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
$sql    = "SELECT user_name,pass FROM `Reg_User` WHERE user_name='$uid' AND pass='$pass'; ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $user_name = $row["user_name"];
        $pass      = $row["pass"];
    }
}
if ($ip_uid == $user_name && $ip_pass == $pass) {
    $_COOKIE['$user_name'] = $user_name;
    echo " <script> alert('Successfully Logged IN');";
    header('Location: http://localhost/TrainProject/Landing_page.php');
} else {
    echo " <script> alert('Wrong Credentials Login failed');";
    header('Location: http://localhost/TrainProject/new_home.html');
}

?>

You're explicitly canceling the form submission: 明确取消了表单提交:

onsubmit="return false"

If you want the form to submit, remove that. 如果要提交表单,请删除该表单。

Change to 改成

<div id="log_btn">
    <section id="form_before_launch">
    <p style="font-family: Arial, Helvetica, sans-serif;">LogIn</p>
    <form action="login.php" id="form" method="POST">
        <div>
            <div>
                **<!-- Fields of Login page -->**
                <input type="text" id="username" name="uname" placeholder="Username" required />
            </div>
            <div>
                <input type="password" id="password" name="pass" placeholder="password" required />
            </div>
            **<!-- Captcha is Displayed in id="ip" & users enters the captcha in id "op" on Submit login page is executed -->**
            <div>
                <input type="text" id="ip" name="ip" />
                <br>
                <input type="text" id="op" name="op" />
            </div>
            <br><br><br>
            <div id="btn">
                <input type="submit" id="submit" value="Log In" />
            </div>
    </form>
    </div>

your problem in the html has the paramter onsubmit="return false" 您在html中的问题具有参数onsubmit="return false"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM