当我使用此代码时,我正在使用PHP将数据从表单发送到mysql数据库:
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
phone VARCHAR(60) NOT NULL,
password VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
email VARCHAR(50),
pelak VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
reg_date TIMESTAMP
)";
它完美无缺,但是当我使用时:
$field_table = $_POST['phone'];
$sql = "CREATE TABLE '{$field_table}' (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
phone VARCHAR(60) NOT NULL,
password VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
email VARCHAR(50),
pelak VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
reg_date TIMESTAMP
)";
它在phpmyadmin中创建表但出错:
“#1146 - 表'username.table_name'不存在”