0

I face the invalid parameter number on this code, can any one help me to understand the nature of this problem

    $q = $_POST["search"]["value"];
    if($mycondition) { 
        //use this part
        $query = "SELECT user_id, username FROM users WHERE user_id = :user_id ";
        //my parameter
        $params = [
            'user_id' => $user_session_id
        ];
    }else {
        //Use
        $query = 'SELECT user_id, username, status FROM users WHERE status = :status AND user_id = :user_id ';
        //my parameters
        $params = [
            'user_id' => $user_session_id,
            'status' => 'muted'
        ];
    }
    if($q !== '') {
        $query .= 'AND (username LIKE :username) ';

        $params['username'] = '%' . $q . '%';
    }
    
    $stmt = $db -> prepare($query);
    //problem start from here
    $stmt->execute($params);

the problem start from this line $stmt->execute($params); with the following message

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in ... the above line

DarkBee
  • 16,592
  • 6
  • 46
  • 58

0 Answers0