gpt4 book ai didi

PHP 登录表单不适用于 mysql

转载 作者:行者123 更新时间:2023-11-30 22:12:28 25 4
gpt4 key购买 nike

<?php
if(array_key_exists("logIn",$_POST))
{
$link = mysqli_connect("dbaddress", "dbname", "dbpassword", "dbuser");

if(!$_POST['regno'])
{
$error .= "Please enter your registration number";
}
if(!$_POST['password'])
{
$error .= "Password is required!";
}
if($error!="")
{
echo "<p>There were errors in your forms!</p>".$error;
}
else
{
$query = "SELECT * FROM `users` WHERE RegistrationNo = '".mysqli_real_escape_string($link, $_POST['regno'])."'";

$result = mysqli_query($link, $query);

$row = mysqli_fetch_array($result);

if (isset($row)) {

$hashedPassword = md5(md5($row['id']).$_POST['password']);

if ($hashedPassword == $row['password']) {

$_SESSION['id'] = $row['id'];
header("Location: after_login.php");
}
else {
$error = "That email/password combination could not be found.";
}
}
else {
$error = "That email/password combination could not be found.";
}
}}
?>

<form method="post">
<center><input type="text" placeholder="Enter Username" name="regno" id="log_username" class="sidelog"/>
<input type="password" placeholder="Enter Password" name="password" id="real_pass" class="sidelog"/>
</br><button id="button_log" type="submit" name="logIn" > GO </button> </center>
</form>

每当我填写并提交表单时,页面都会重新加载。 header 不起作用。我似乎无法弄清楚为什么。如果我将表单留空,则错误字符串会正确显示。我对密码使用了md5加密。我将数据库中 id 的 md5 与密码连接起来,然后 md5 加密了结果字符串。

最佳答案

试试这个可能对你有帮助,

     if ($hashedPassword == $row['password']) {
$_SESSION['id'] = $row['id'];
header("Location: after_login.php");
die();
}

关于PHP 登录表单不适用于 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39640843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com