简体   繁体   English

MYSQL问题(创建表)

[英]MYSQL Problems (Creating a Table)

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! 除非$ TQ,$ TN或$ CR在单词中包含空格时它会失败! Here is the error message: A table must have at least 1 column 这是错误消息:一个表必须至少有1列

Does anyone know how I can fix this? 有谁知道我该如何解决?

您必须用`括住表名:

$sql="CREATE TABLE `".$URL."` (Image BLOB,Rating INT(255),Id INT KEY AUTO_INCREMENT)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM