我正在使用php在我的数据库中创建一个MYSQL表:
$sql="CREATE TABLE $URL(Image BLOB,Rating INT(255),Id INT KEY AUTO_INCREMENT)";
但是,它出错并说:表必须至少有一列。
为什么要这样做?
以下是用于创建表的完整php文件:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="questapic"; // Database name
$tbl_name="tabledirector";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
// 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']);
$datetime=date("d/m/y"); //create date time
$R1=rand(5000, 15000000);
$R2=rand(5000, 15000000);
$R3=rand(5000, 15000000);
$URL = $TN . $R1 . $TQ . $R2 . $CR . $R3;
$URL=str_replace(" ","#%","$URL");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="INSERT INTO $tbl_name(URL,topic)VALUES('$URL','$TQ')";
$result=mysql_query($sql);
$sql="CREATE TABLE $URL(Image BLOB,Rating INT(255),Id INT KEY AUTO_INCREMENT)";
$result=mysql_query($sql);
if (!$result) die (mysql_error());
mysql_close();
header("location:Your_Special_Code_Is.php?id=$URL");
?>
答案 0 :(得分:1)
尝试:
$sql="CREATE TABLE ".$URL."(Image BLOB,Rating INT(255),Id INT KEY AUTO_INCREMENT)";