在访问数据库后得到result值,前提是$relust为true,就是没有发生错误连接情况,但是查询的条件由于不满足导致返回值为空,此时判断就不能用!来决定是否有返回数据了,经过书籍搜索,用result的长度来判断,此处用到mysql_numrows($result),如果为空就小于等于0,经验证,可以使用 代码逻辑如下:

$query="SELECT password FROM user WHERE name='$name'";

$result=mysql_query($query);
if (!$result) {
  echo "connect error!!!".mysql_error();
}else {
  if (mysql_numrows($result)<=0) {
    $json['status'] = 0 ; //用户名不存在
     echo $callback.'('.json_encode($json).')';
    }else{
      while ($row = mysql_fetch_array($result))
       {
        $db_password = $row['password'];
        if ($db_password == $password) {
          $json['data']['name']=$name;
          $json['data']['passwoed']=$db_password;
          $json['status'] = 1;//登录成功
          echo $callback.'('.json_encode($json).')';
        }else {
          $json['status']=2;//密码错误
          echo $callback.'('.json_encode($json).')';
        }
      }
  }
}

相关文章:

  • 2022-03-05
  • 2021-12-10
  • 2021-11-27
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-22
  • 2021-12-05
  • 2021-10-10
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案