创建一个带有变量名的sql表

My dilemma is I have successfully been able to create an SQL table with a variable name in the past, though for some reason am now running into trouble in doing so with nearly the exact code as before. For context, when I remove the variable in the SQL statement the code works. Below is my code that does function properly and creates the table with a variable name:

function RandomString($length) {
$keys = array_merge(range(0,9), range('a', 'z'), range('A', 'Z'));

$key = "";
for($i=0; $i < $length; $i++) {
    $key .= $keys[mt_rand(0, count($keys) - 1)];
}
return $key;
}

$table = "acct_".RandomString(10); 

$query1 = "CREATE TABLE $table (ID int AUTO_INCREMENT PRIMARY KEY, 
account_id text, uemail text, uaccess text, owner text, dob text, 
billingaddress text, accountstatus text, idverification text, notes1 text, 
dtype1 text, domain1 text, register1 text, expiration1 text, dstatus text, 
reasonrejected text, prodtype text, prodname text, prodstatus text, 
prodlimit text, prodapprby text, supportdate text, supportsubject text, 
supportgroup text, logindate1 text, loginreason text, loginby text, 
requesttype text, atoreason text, resolvedato text, cardname text, cardbrand 
text, cardnum text, cardexpiry text, chargemethod text, invoicenum text, 
invoiceamount text, duedate text, paydate text, invoicestatus text, 
loginuser text, loginaction text, loginip text, loginlocation text, 
logindate text, logintime text, supportpin text)";

mysqli_query($database, $query1);

Followed by my code (for a separate application) that does not properly function in creating the table with a variable name. Please note, when I remove the variable and make the table name constant, the code runs successfully:

function RandomString($length) {
$keys = array_merge(range(0,9));

$key = "";
for($i=0; $i < $length; $i++) {
    $key .= $keys[mt_rand(0, count($keys) - 1)];
}
return $key;
}

$ticketnumber = RandomString(6);

$AddTicket = "CREATE TABLE $ticketnumber (ID int AUTO_INCREMENT PRIMARY KEY, 
TicketNumber text, Queue text, Assignee text, User_Name text, TStatus text, 
CCs text, Tags text, CSAT_Score int, CSAT_Comment1 text, CSAT_Comment2 text, 
TSubject text, User_Email text, Message text, Internal_Note text, Events 
text, Requested text)";

mysqli_query($database, $AddTicket);