1

HELP! Code not creating a table, does this look ok? How do you usually debug to find out what is not working in 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
  • 1
    You should use a newer SQL extension (PDO or MySQLi for instance). The mysql extension is deprecated. Commented Feb 2, 2014 at 6:02

1 Answer 1

10

The last line doesn't need a comma ,

$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)
)";

I tried out this code in phpMyAdmin first and found that error ^

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.