我放入我的登录表单代码的详细信息将返回为不正确的,即使它们是,为什么?
问题描述:
这里是我的代码:我放入我的登录表单代码的详细信息将返回为不正确的,即使它们是,为什么?
<?php
session_start();
include_once('../includes/connection.php');
if (isset($_SESSION['logged_in'])){
\t
}else{
\t
\t if (isset($_POST['username'], $_POST['password'])) {
\t \t $username= $_POST['username'];
\t \t $password= md5($_POST['password']);
\t \t
\t \t
\t \t if(empty($username) or empty($password)) {
\t \t \t
\t \t \t $error = 'All fields are required!';
\t \t \t
\t \t \t
\t \t }else{
\t \t \t $query = $pdo->prepare("SELECT * FROM users WHERE user_name = ? user_password = ?");
\t \t \t
\t \t \t $query->bindValue(1, $username);
\t \t \t $query->bindValue(2, $password);
\t \t \t
\t \t \t $query->execute();
\t \t \t
\t \t \t
\t \t \t $num = $query->rowCount();
\t \t \t
\t \t \t if ($num==1){
\t \t \t \t
\t \t \t \t
\t \t \t \t $_SESSION['logged_in'] = true;
\t \t \t \t header('Location: index.php');
\t \t \t \t exit();
\t \t \t \t
\t \t \t \t
\t \t \t \t
\t \t \t }else{
\t \t \t \t
\t \t \t $error='Incorrect details!';
\t \t \t
\t \t \t }
\t \t \t
\t \t }
\t \t
\t \t
\t \t
\t }
\t
\t
\t
?>
<html>
\t <head>
\t \t <title>CMS Tutorial</title>
\t \t <link rel="stylesheet" href="../assets/style.css" />
\t </head>
\t <body>
\t \t <div class="container">
<a href="index.php" id="logo">CMS</a>
\t \t
<?php if(isset($error)) { ?>
<small style="color:#aa0000;"><?php echo $error; ?></small>
<?php } ?> \t
\t \t
\t \t <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" /> \t \t \t \t
\t \t </form>
\t \t </div>
\t </body>
</html>
<?php
\t
\t
\t
}
?>
我不知道在我的错误是,试图找到一个错误,但我找不到它,我进入了代码的最新代码是“} else {$ query = $ pdo-> etc ..”但我认为那里没有任何错误......如果有人能帮助我,我会非常感激!还有你们不必给我发送整个代码回答一个简单的答案或提示将有所帮助。 :d!
答
您的查询需要一个AND:
$query = $pdo->prepare("SELECT * FROM users WHERE user_name = ? AND user_password = ?");
+1
谢谢你的魅力!在十分钟内将您的评论标记为答案!再次感谢你! –
您的查询需求和之前USER_PASSWORD =? 。也请不要使用md5作为密码。使用php内置的password_hash和password_verify – Akintunde007
哇,这是快速的谢谢你!这样一个愚蠢的错误:D –
你不会忍受这个,是吗? –