Reputation: 199
I am using info from a previous form to create a jumbled string. I use this string to name a table that I create in the code below:
// get data that sent from form
$TN = mysql_real_escape_string($_POST['name']);
$TQ = mysql_real_escape_string($_POST['q']);
$CR = mysql_real_escape_string($_POST['creator']);
//Add Randomness to String
$datetime=date("d/m/y"); //create date time
$R1=rand(5000, 150);
$R2=rand(5000, 10000);
$R3=rand(5000, 15000000);
//Create String called URL
$URL = $TN . $R1 . $TQ . $R2 . $CR . $R3;
//Eliminate Spaces
$URL=str_replace(" ","#%","$URL");
//echo $URL;
//add name of table in a table containing the names of these tables
mysql_select_db("$db_name")or die("cannot select DB");
$sql="INSERT INTO $tbl_name(URL,topic)VALUES('$URL','$TQ')";
$result=mysql_query($sql);
//Create the Table
$sql="CREATE TABLE ".$URL."(Image BLOB,Rating INT(255),Id INT KEY AUTO_INCREMENT)";
$result=mysql_query($sql);
This code works great! Except it fails whenever $TQ,$TN or $CR contain a space in the word! Here is the error message: A table must have at least 1 column
Does anyone know how I can fix this?
Upvotes: 0
Views: 41
Reputation: 4284
You must enclose the table name with `:
$sql="CREATE TABLE `".$URL."` (Image BLOB,Rating INT(255),Id INT KEY AUTO_INCREMENT)";
Upvotes: 1