There are a few things you can do to fix this and prevent it from happening. Barmar is right, you need to pass the variable $player1 into your function otherwise it will be out of scope.
What's most likely happening is your query is returning an error but you're not catching it so when you try to echo $row['id'] its just empty.
While developing i always add:
error_reporting(E_ALL);
ini_set("display_errors", "on");
to the top of my php files to see all error and warnings.
More importantly is to catch errors, you can do something like this to ensure that your query is working properly:
function gameID($player1){
$gameIDsql = mysql_query("SELECT id FROM game WHERE player1='$player1' ORDER BY id DESC LIMIT 1");
if(!$gameIDsql)
throw new Exception=("Unable to get id for player: " . $player1 . " query returned an error: " . mysql_error());
$row = mysql_fetch_assoc($gameIDsql);
echo $row['id'];
}
Generally you it's just good practice to assume that if something can fail that it will so its best to include code that will handle the errors.