mysql – How to check a value exist in column and update

I’m actually doing a leaderboard but encountered a problem
I’m trying to check in my db if a player already exist and if his new score i greater than the previous one update it:

$query = mysqli_query("SELECT Count * FROM `score` WHERE playerID='".$playerID."'");

    if(mysqli_num_rows($query) != 0){
        if ($score > $row('score')){
    $sql = mysqli_query($con, "REPLACE INTO $db_name.$db_table (name, score, playerID)
                               VALUES ('$name','$score','$playerID');" );
        } else {
            // ERROR MSG: Your new score is lower.(not updating the database)
        }
        } else {
    $sql = mysqli_query($con, "INSERT INTO $db_name.$db_table (name, score, playerID)
                               VALUES ('$name','$score','$playerID');" );
    }

I don’t know why but it’s just duplicate the new entry.
I read several exemples but nothing work or codes are too old.