viewing paste Unknown #5449 | PHP

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
function add_player_to_leaderboard(\mysqli $dbh, $player)
        {
                $player = strval($player);
               
                $sth = $dbh->prepare("SELECT COUNT(*) AS `num_rows` FROM `db_checks` WHERE `username`=? LIMIT 1;");
                $sth->bind_param('s', $player);
                $sth->execute();
               
                $sth->bind_result($num_rows);
                $sth->fetch();
               
                $player_exists = (bool)($num_rows > 0); // don't think (bool) is necessary but i did it anyways to clarify the meaning
 
                $sth->close();
                       
                if (!$player_exists)  
                {
                        insert_new_player($dbh, $player);
                       
                        echo "Inserted new entry";
                        return false;
                }
                else  
                {
                        echo "Name exists. - Unfinished  ";
                        return true;
                }
        }
Viewed 272 times, submitted by unknown.