我有这个验证登录脚本的代码,我有另一个代码,一旦他输入电子邮件地址和密码登录就检查用户信息但是我找不到连接这些两个脚本的方法一起 我希望首先验证表单,然后在成功验证后,在登录过程中检查信息,在数据库中检查输入的信息
的login.php
<?php
$emailErr = $passwordErr = "";
$email = $password = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(empty($_POST['email'])) {
$emailErr = "*email is required";
} else {
$email = test_input($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "*ivalid email format";
}
}
if(empty($_POST['password'])) {
$passwordErr = "*password is required";
} else {
$password = test_input($_POST['password']);
}
}
//the function to filter the input
function test_input($data) {
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<head>
<title>user login</title>
<link href="login-style.css" rel="stylesheet">
<style>
.error {
color: #FF0000;
font-size: 12px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="wrapper">
<p>please either login or <br> <a href="regestir.php">click here to regestir</a>
<form method="POST" action="login-process.php" name="loginform">
<span class="error"> <?php echo $emailErr;?></span>
<input type="text" name="email" placeholder="email" value="<?php echo $email;?>">
<span class="error"><?php echo $passwordErr;?></span>
<input type="password" name="password" placeholder="password" value="<?php echo $password;?>">
<input type="submit" name="submit" value="login">
</div>
<body>
</html>
登录-process.php
<?php
include('user-config.php');
session_start();
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
if(isset($email) && isset($password)) { //check if it is set or not
$sql = "select * from data where email = '$email' and password = '$password' ";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count == 1) {
$_SESSION['useremail'] = $email;
$_SESSION['userpassword'] = $password;
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['last_name'] = $row['last_name'];
$_SESSION['gender'] = $row['gender'];
#print_r($_SESSION); show the values stored in the sessions
header("location: welcome.php");
} else {
echo 'username or passwrod is incorrect';
}
}
?>