php - 无法通过数据库查询验证用户

标签 php mysql database mysqli

我的代码没有运行。它总是打印$errmassage="用户名或密码不正确";。可能是我的查询不完美。但我尝试了很多次来计算num_rows。但没有成功。请任何人帮助我。

$search= "SELECT * from registermember WHERE email='$username' AND password='$password'";
    $result=mysqli_query($conn,$search);
    $checkrow=mysqli_num_rows($result);
    if ($checkrow > 0) {
        $cookie=setcookie("$username",md5('$password'), date()+7200,"/");
        $_SESSION['user']=$username;
        header("location:mainpage.php");
    }
    else{
        $errmassage="username or password incorrect";
    }

最佳答案

首先要做

echo $search;
die;

并在 phpMyAdmin 或其他服务器上测试查询。确保问题是代码或 SQL。

关于php - 无法通过数据库查询验证用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43431334/

相关文章:

php - 如何验证表单字段xml中的电话号码

php - 博彩社区的数据库设计

php - 只是为了好玩 - 开始解决一个棘手的 PHP 逻辑问题

php - 在 Woocommerce 中添加新产品时自动添加所有产品属性

android - 在 Android 应用程序中向选定用户发送通知

MySQL - 使用字符串作为主键

MYSql - 在 Zend Db 中使用相关子查询

php - 监听 mySQL 数据库中的更改(使用 PHP)

sql - 单个 SQL 查询中的分组和聚合字段

php - 在 PHP 函数中检索记录