php mysql 不检查用户表上的用户名和密码

标签 php html mysql verify

登录页面似乎无法正常工作。它不会验证用户表上的用户名密码,因此不允许登录。

PHP

 if(isset($_POST['submit']))
 {
     $userName=$_POST['userName'];
     $passWord=$_POST['passWord'];
     $result=mysqli_query($con,"select *from Users where `userName` ='$userName' and `passWord` ='$passWord'");
     if($result)
     {
          //echo "Successfully deleted".$id;
          $count=mysqli_num_rows($result);       
          //echo $count;
     }
     if($count==1)
     {
          $_SESSION['username']=$username;
          $_SESSION['passWord']=$passWord;
          header("location:users.php");
     }
     else
     {      
          header("location:index.php");  
     }
 }
 ?>

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <link href="index.css" rel="stylesheet" type="text/css" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Sign in</title>
</head>
<body>
  <div id="signin">
    [ <a href="signup.php">Sign Up</a> ]
    [ <a href="signin.php">Sign In</a> ]
  </div>
  <div id="clear"></div>
  <div class="navbar">
    <ul>
      <li><a href="concerts.php" target="_self">Concert</a></li>
      <li><a href="restaurants.php" target="_self">Restaurant</a></li>
      <li><a href="sports.php" target="_self">Sports</a></li>
    </ul>
  </div>
  <form name="signin" method="post" action="signin.php" id="form">
    Member Login <br /><br />
    Username<input name="userName" type="text"><Br />
    Password</td><input name="passWord" type="password"><br /><br />
    <input type="submit" name="submit" value="submit">
  </form>
</body>
</html>

此代码没有从用户表中获取 id_cust 来存储在 $id 中 它从登录页面获取正确的用户名

<?php 
$result=mysqli_query($con, "select * from Users where `userName` ='$userName'");
$row = mysqli_fetch_array($result);
$id = $row['id_cust'];

http://pastebin.com/RmBz1yL0

最佳答案

尝试将代码更改为以下内容。

 if($result)
        {
            //echo "Successfully deleted".$id;
            $count=mysqli_num_rows($result);       
            //echo $count;

            if($count==1)
            {
                   $_SESSION['userName']= $userName;
                   $_SESSION['passWord'] = $passWord;
                  header("location:users.php");
           }
           else
           {      
                  header("location:index.php");  
           }

        }

关于php mysql 不检查用户表上的用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23186399/

相关文章:

java - 尽管我已经尝试过 SQL 中的代码,但我在 WHERE 子句中遇到错误

php - Codeigniter Ajax请求与mysql一样查询编码字符串为字符

javascript - Ajax 不工作。我需要页眉和页脚不要每次都重新加载。你能帮助我吗?

javascript - 使 slider 箭头在魔术 slider 中始终可见

php - 是否有其他序列浏览器解释为 HTML 特殊字符?

php - 轮类日历 - 根据给定模式确定轮类

html - 左对齐、右对齐和居中对齐的 div

mysql - 检索为 Mysql 中的树数据定义的最后一个值

php - 登录后 Wordpress 重定向到引用页面

php - 使用 CASE 比较 MySQL 中的日期