Page 1 of 1

Let's Play Find The Error! (Create Table Script)

Posted: Fri Jan 07, 2005 10:17 pm
by SilverMist
Code:
createtable.php

Code: Select all

<?php 

$server = "localhost";	// server to connect to.
$database = "*****";	// the name of the database.
$db_user = "*****";	// mysql username to access the database with.
$db_pass = "*****";	

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// create table on database
$create = "CREATE TABLE `members` (
  `id` int(5) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `uname` varchar(50) NOT NULL default '',
  `email` varchar(200) NOT NULL default '',
  `password` varchar(10) NOT NULL default '',
  `bmonth` varchar(40) NOT NULL default '',
  `byear` varchar(40) NOT NULL default '',
  `bday` varchar(40) NOT NULL default '',
  `status` enum('N','Y') NOT NULL default 'N',
  `code` char(6) NOT NULL default '',
  `joindate` date NOT NULL default '0000-00-00',
  `login` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`,`email`,`uname`),
  UNIQUE KEY `uname`
  UNIQUE KEY `email` )
 TYPE=MyISAM AUTO_INCREMENT=1;";

mysql_query($create)
or die ("Could not create tables because ".mysql_error());
echo "Complete.";
?>
Error:

Code: Select all

Could not create tables because You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIQUE KEY `email` ) TYPE=MyISAM AUTO_INCREMENT=1' at line 17
?>

Posted: Fri Jan 07, 2005 10:18 pm
by feyd
missing a comma.

Posted: Fri Jan 07, 2005 10:22 pm
by SilverMist
Huh? Thanks, but where? I can't find any :cry:

Posted: Fri Jan 07, 2005 10:26 pm
by feyd
line 32 of your post.

Posted: Fri Jan 07, 2005 10:29 pm
by SilverMist
Added it,

Code: Select all

TYPE=MyISAM, AUTO_INCREMENT=1;";
(forgive me if this is wrong, it's like 2AM)
Error Now:

Code: Select all

Could not create tables because You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIQUE KEY `email` ) TYPE=MyISAM, AUTO_INCREMENT=1' at line 1

Posted: Fri Jan 07, 2005 10:39 pm
by feyd
look at your original post. Line 32 of the posted code.

unique key uname...

Posted: Sat Jan 08, 2005 3:50 am
by kondro
The field names in your key assignments should be surrounded by ( )

e.g. UNIQUE KEY (`uname`)

also, don't forget the commas after each key assignment as well (except the last one of course)