此表单用于从用户获取登录详细信息。提供 登录页面中执行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>
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');
}
?>
答案 0 :(得分:7)
您明确取消表单提交:
onsubmit="return false"
如果您希望提交表单,请将其删除。
答案 1 :(得分:1)
更改为
<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>
html中的问题包含参数onsubmit="return false"