Ok, i wrote some code in a classic way without mysqli prepared statements and it works just fine, but when i try with mysqli prepared statement it doesn't work properly. Here is the code on classic way:

public function search($search){
            $allResults = array();
            $query = mysqli_query($this->con, "SELECT user_id, username, screenName, profileImage, profileCover FROM users WHERE username LIKE '$search%'");
            if(mysqli_num_rows($query) > 0) {
                while($row =  mysqli_fetch_assoc($query)){
                    $allResults[] = $row;
                }
                return $allResults;
            }else {
                return false;
            }
}

And i get my results. enter image description here But when i try mysqli prepared statements:

public function search($search){
        $allResults = array();
        $stmt = $this->con->prepare("SELECT user_id, username, screenName, profileImage, profileCover FROM users WHERE username LIKE ?");
        $s = $search.'%';
        $stmt -> bind_param('s', $s);
        $stmt -> execute();
        $stmt -> store_result();
        if($stmt->num_rows > 0) {
            while($row =  $stmt -> fetch()){
                $allResults[] = $row;
            }
            return $allResults;
        }else {
            return false;
        }
}

i get this: enter image description here

The code above is in class.php, and the other file, search.php would be: enter image description here

I know it's long question, but what am i missing here, any tips?

0 Answers