我目前正在开发自己的 CMS。
由于某种原因,它似乎不接受我的登录详细信息......代码是:
<?php
session_start();
include_once('../includes/connection.php');
if (isset($_SESSION['logged_in'])) {
// display index
} else {
if (isset($_POST['username'], $_POST['password'])) {
$username = $_POST['username'];
$password = md5($_POST['password']);
if (empty($username) or empty($password)){
$error = 'Please enter all of the fields!';
} else {
$query = $pdo->prepare("SELECT * FROM users WHERE user_name = ? AND user_password = ?");
$query->bindValue(1, $username);
$query->bindValue(2, $password);
$query->execute();
$num = $query->rowCount();
if ($num == 1) {
// user entered correct
$_SESSION['logged_in'] = true;
header('Location: index.php');
exit();
} else {
//user entered false
$error = "Incorrect details!";
}
}
}
?>
<html>
<head>
<title>CMS</title>
<link rel="stylesheet" type="text/css" href="../assets/style.css" />
</head>
<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>
<br /><br />
<?php if (isset($error)) { ?>
<small style="color:#aa0000;">
<?php echo $error; ?>
<br /><br />
</small>
<?php } ?>
<form action="index.php" method="post" autocomplete="off">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Login" />
</form>
</div>
</body>
</html>
<?php
}
?>
连接是:
> <?php
>
> try { $pdo = new PDO('mysql:host=localhost;dbname=website', 'root',
> ''); } catch (PDOException $se) { exit('Database error.'); }
>
>
> ?>
每次我尝试使用正确的详细信息登录时,它只会显示“不正确的详细信息”
有任何想法吗?