我是编程新手,这里我正在创建简单的注册和登录表单,我的注册表单可以正常运行,它可以正确地在数据库中注册用户提供的输入,但是当我在登录表单中使用相同的用户名和密码时,它不起作用,它没有登录用户,我正在使用准备好的语句,请您提供任何帮助,如果我犯了一些明显的错误,请原谅我。
谢谢....
这是我的HTML代码
<!DOCTYPE html>
<html>
<head>
<title>Login page</title>
</head>
<body>
<form method="POST" action="register.php">
<div class="container">
<label>Username :</label>
<input type="text" name="username" placeholder="Username"><br><br>
<label>Password :</label>
<input type="Password" name="password" placeholder="Password"><br><br>
<button type="sumbit" value="sumbit" name="sumbit">Register</button>
</div>
</form>
<br><br>
<form method="POST" action="login.php">
<div class="container">
<label>Username :</label>
<input type="text" name="username" placeholder="Username"><br><br>
<label>Password :</label>
<input type="Password" name="password" placeholder="Password"><br><br>
<button type="sumbit" value="sumbit" name="login">Login</button>
</div>
</form>
</body>
这是我的登录代码:
<?php
include "register.php";
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users where username ='$username' && password='$password'";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username',$username);
$stmt->bindParam(':password',$password);
$stmt->execute();
$stmt->bind_result($username,$password);
$stmt->store_result();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->row ==1){
$_SESSION['login'] = $username;
header("location: home.php");
}else{
echo "Username and password is incorrect";
}
?>
慕的地8271018
紫衣仙女