// Make a temporary table and find if there is a temp table with the same // name as we are about to name it for ($x = 1; $x < 1000000; $x++) { if (mysql_query("SELECT * FROM temp$x")) { $temptabledone = 0; } else { $temptabledone = 1; break; } }

so when you say "doesn't work", what does that mean? sorry, i don't want to step through all of your code to make sure your code is safe when you are probably getting an error that has the solution buried inside it.