All of your queries have syntax errors. You do NOT use '
quotes to delimit field names. If you'd bothered actually CHECKING if errors were occuring, you'd have been informed about this:
CREATE TABLE IF NOT EXISTS '$table' ( 'ID' INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( 'ID' ) )
^-- ^-- ^--^--- ^--^-
remove ALL of the indicated quotes, on ALL of your queries. And then rewrite them as:
$result = mysql_query(...) or die(mysql_error());