mysqli将数据插入phpmyadmin的问题

I know this Question is asked a million times, so I apologize in advance! I am trying to insert data with mysqli to database and it works offline with XAMPP, but when I implement it on my actual website it does not work. My code:

$result2 = $connection->query('SELECT fn FROM '.$rapi.' WHERE fn = 
   "'.$names['from_name'].'" ');
if($result2->num_rows == 0) {
     //if follower doesnt exist in database put him in
    mysqli_query($connection, 'INSERT into '.$rapi.' (fn, ft) VALUES 
          ("'.$names['from_name'].'", "'.$names['followed_at'].'")');

There are no errors on the page as well. If I try inserting data with SQL manually it works. Is the code provided outdated ? Or could it be the hosting provider error ?