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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

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

Post 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
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

missing a comma.
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

Post by SilverMist »

Huh? Thanks, but where? I can't find any :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

line 32 of your post.
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look at your original post. Line 32 of the posted code.

unique key uname...
kondro
Forum Newbie
Posts: 3
Joined: Sat Jan 08, 2005 3:20 am

Post 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)
Post Reply