为什么我的 $type 变量保存为 'Admin''?

why does my $type variable get saved as 'Admin''?

我正在尝试获取我的 table 中的管理员数量,它确实可以正常工作,但是现在我为两个 table 添加了内部联接,我得到了这个错误,即管理员一词中有一个额外的 '我不知道如何删除它 所以这是我在 userc.php 中的功能:

    function admincountsearch($key)
    {
        $con = config::getConnexion();
        $sql = "SELECT  user.username,user.name,user.lastname,user.id, 
                    user.email, user.image, user.verified, usero.type, 
                    usero.description,usero.ban 
            FROM user 
                INNER JOIN usero ON user.id_o = usero.id 
            WHERE user.username LIKE :keyword 
                OR user.id LIKE :keyword 
                OR user.name LIKE :keyword 
            WHERE usero.type=:type ";
        $stmt = $con->prepare($sql);
        $type ="Admin" ;
        $stmt->bindValue(':keyword', '%' . $key . '%', PDO::PARAM_STR);
        $stmt->bindValue(':type',$type, PDO::PARAM_STR);
        $stmt->execute();
        $stmt->fetch();
        $results = $stmt->rowCount();
        return $results;
    }

这是我在 find.php 中的称呼:

<span class="info-box-number"><?php echo $userc->admincountsearch($key); ?></span>

这是我得到的错误:

: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE usero.type='Admin'' at line 2 in C:\xampp\htdocs\Project\Integre\Controller\userc.php:458 Stack trace: #0 C:\xampp\htdocs\Project\Integre\Controller\userc.php(458): PDOStatement->execute() #1 C:\xampp\htdocs\Project\Integre\Views\find.php(200): userc->admincountsearch('g') #2 {main} thrown in

您的语句中有 2 个 WHERE 个子句。 你可能是说

SELECT
  user.username,
  user.name,
  user.lastname,
  user.id,
  user.email,
  user.image,
  user.verified,
  usero.type,
  usero.description,
  usero.ban
FROM
    user
INNER JOIN usero ON
    user.id_o = usero.id
WHERE (
  user.username LIKE :keyword OR
  user.id LIKE :keyword OR
  user.name LIKE :keyword
) AND
usero.type=:type