所以我花了很长时间来尝试这个登录,它在php开发服务器上确实工作了一段时间。然而,它不知何故出了故障,每次我按下submit时都会重新加载。我已经仔细检查了数据库,所以我不太确定。只是需要一点帮助来解决代码中可能出现的错误。已尝试更改!也为空以进行设置
<?php
include 'Database/connect.php';
?>
<?php
$username= $_POST['user'];
$password= hash("sha256", $_POST['pass']);
$statement = $db->prepare('SELECT * FROM User WHERE username=? AND password=?');
$statement->bindValue(1, $username);
$statement->bindValue(2, $password);
$result = $statement->execute();
if(isset($username) && isset($password)){
if(empty($result->fetchArray(SQLITE3_ASSOC))){
echo "<script>alert('Invalid Credentials')</script>";
}
else{
session_start();
$_SESSION['user'] = $username;
$random = md5(rand(1,1000)); //encoded with md5, avoid bad string output.
setcookie($username, $random, time()+3600);
header("Location: Blog/home.php");
}
}
?>
<form action='index.php' method="POST">
<input type="email" id="exampleInputEmail1" class="form-control" id="user"
placeholder="Email" style="margin-bottom:1vw;">
<input type="password" id="exampleInputPassword1" class="form-control" id="pass"
placeholder="Password" style="margin-bottom:1vw;">
<input type="checkbox" required id="privacypolicycheckbox" name="privacypolicycheckbox"
value="check">
<label for="privacypolicycheckbox">I have read and agreed to the <a style="color:blue; "
onclick="myFunction()">policy
documents</a></label><br>
<input type="submit" class="btn btn-block btn-danger" value="Log In" name="sumbit-btn">
</form>发布于 2020-10-24 14:53:46
<input type="email" id="exampleInputEmail1" class="form-control" id="user"
placeholder="Email" style="margin-bottom:1vw;">您应该添加到Html以获得name="user"的用户名。
<input type="password" id="exampleInputPassword1" class="form-control" id="pass"
placeholder="Password" style="margin-bottom:1vw;">并将name="pass"设置为获取密码表单html
$username=$_POST['user'];
$password=$_POST['pass'];
$sql = "SELECT * FROM prepare WHERE usrename='".$username."' and password='".$password."' ";
$result = $conn->query($sql);
if (mysqli_num_rows($result) == 1)
{
echo "<center><h2> Login Successfully</h2> </center> ";
}
else
{
echo " <center><h2>Invalid Login Details </h2> </center> ";
}您可以在PHP中使用此代码来获取登录数据
发布于 2020-10-24 15:41:18
您需要使用html中的“$_POST”属性将值传递给名称数组。
<input type="email" name="user" id="exampleInputEmail1" class="form-control" id="user" placeholder="Email" style="margin-bottom:1vw;">
<input type="password" name="pass" id="exampleInputPassword1" class="form-control" id="pass" placeholder="Password" style="margin-bottom:1vw;">https://stackoverflow.com/questions/64510653
复制相似问题