MySQL和PHP表没有被创建

时间:2014-02-02 05:38:12

标签: php mysql sql create-table

HELP!代码没有创建表,这看起来不错吗?您如何通常调试以找出MySQL中无法正常工作的内容?

<?php  
// Connect to the file above here  
require "connect_to_mysql.php"; 

$sqlCommand = "CREATE TABLE products (
id INT(11) NOT NULL auto_increment,
product_name VARCHAR(255) NOT NULL,
price VARCHAR(64) NOT NULL, 
details text NOT NULL,
category varchar(64) NOT NULL,
date_added date NOT NULL,
PRIMARY KEY(id),
UNIQUE KEY product_name(product_name),
)";

mysql_query($sqlCommand) or die(mysql_error());
?>

1 个答案:

答案 0 :(得分:9)

最后一行不需要逗号,

$sqlCommand = "CREATE TABLE products (
id INT(11) NOT NULL auto_increment,
product_name VARCHAR(255) NOT NULL,
price VARCHAR(64) NOT NULL, 
details text NOT NULL,
category varchar(64) NOT NULL,
date_added date NOT NULL,
PRIMARY KEY(id),
UNIQUE KEY product_name(product_name)
)";

我先在phpMyAdmin中尝试了这段代码,发现错误^