1
CREATE TABLE  `users` (

 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
 `type` ENUM(  `member` ,  `admin` ) NOT NULL ,
 `username` VARCHAR( 30 ) NOT NULL ,
 `email` VARCHAR( 80 ) NOT NULL ,
 `pass` VARBINARY( 32 ) NOT NULL , 
 `first_name` VARCHAR( 20 ) NOT NULL , 
 `last_name` VARCHAR( 40 ) NOT NULL , 
 `date_expires` DATE NOT NULL , 
 `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 `date_modified` TIMESTAMP NOT NULL DEFAULT `0000-00-00 00:00:00` ,
PRIMARY KEY (  `id` ) , 
UNIQUE KEY  `username` (  `username` ) ,
UNIQUE KEY  `email` (  `email` ) 
) ENGINE = MYISAM DEFAULT CHARSET = utf8; 

MySQL said:

#1064 - 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 'member,admin) NOT NULL, username VARCHAR(30) NOT NULL, email VARCHAR(80)' at line 3

The shared server I am using, uses 4.4. Thanks for reading. I am an absolute novice, having only been learning php/mysql for one month, so please speak in layman's terms.

4
  • Don't use markup (eg <br/>) when posting. Instead use the code section toggle in the edit toolbar. Commented Feb 27, 2012 at 16:36
  • Looks like you overcompensated for the last issue. Commented Feb 27, 2012 at 16:38
  • @Paul Bellora: that's SO's formatting getting confused by # character Commented Feb 27, 2012 at 16:40
  • @Mchl - I meant that his last syntax error was using single-quote for table/column names, and it looks like he switched to back-ticks for everything, including enums. Commented Feb 27, 2012 at 16:50

3 Answers 3

5

You need to quote ENUM values

type ENUM( 'member' , 'admin' ) NOT NULL ,

not backtick them as you do now

Same thing for this line

`date_modified` TIMESTAMP NOT NULL DEFAULT `0000-00-00 00:00:00`

should be

`date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'
Sign up to request clarification or add additional context in comments.

3 Comments

Thank-you @Anthony Grist & @Mchl . This may be an incredibly stupid question, but why do you use ' rather than ` here?
Because backticks ` are for denoting database objects like tables and columns, while ' is for delimiting string values.
@Matthew: Please read the manual; all of this information is there (dev.mysql.com/doc/refman/5.0/en/string-literals.html & dev.mysql.com/doc/refman/5.0/en/identifiers.html).
1

This page indicates that your ENUM values should be strings, so need to be surrounded by single quotes.

type ENUM( 'member' , 'admin' ) NOT NULL

Comments

0

okey fixed it here is it :)

CREATE TABLE `users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
type ENUM( 'member' , 'admin' ) NOT NULL ,
`username` varchar(30) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`first_name` varchar (15) NOT NULL,
`last_name` varchar (30) NOT NULL,
`gender` ENUM('male',  'female') NOT NULL default 'male',
`email` varchar(50) NOT NULL default '',
`skype` varchar(50) NOT NULL default 'Not Specified',
`facebook` varchar(150) NOT NULL default 'Not Specified',
`location` varchar(100) NOT NULL default 'Not Specified',
PRIMARY KEY (`id`),
UNIQUE KEY (`email`),
KEY (`email`, `password`)
) ENGINE = MYISAM DEFAULT CHARSET = utf8;

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.