0

I am trying to follow a simple lesson in web tourist. I tried to modify the code given for my needs. And it spits error with modification:

#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 ''id'), UNIQUE KEY ('email'), KEY ('email', 'pass') ) ENGINE = MYISAM DEFAULT ' at line 13

ORIG CODE:

CREATE TABLE `users` ( 
`id` int(11) NOT NULL auto_increment, 
`username` varchar(30) NOT NULL default '', 
`password` varchar(255) NOT NULL default '', 
`email` varchar(40) NOT NULL default '', 
`msn` varchar(250) NOT NULL default 'Not Specified', 
`aim` varchar(250) NOT NULL default 'Not Specified', 
`location` varchar(36) NOT NULL default 'Not Specified', 
PRIMARY KEY (`id`) 
) TYPE=MyISAM; 

MY EDIT:

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', 'pass')
) ENGINE = MYISAM DEFAULT CHARSET = utf8;
0

2 Answers 2

2

You are mixing up back-ticks and quotes. This is the general rule to live by: back-ticks are used to enclose table structure (table names, table columns, constraint names etc). Quotation marks are used to enclose row values - aka, the actual data that is being entered into the table. You won't use quotation marks in a DDL statement unless you are specifying default values.

Your error is on primary, unique and index keys in your statement.

PRIMARY KEY ('id'),
UNIQUE KEY ('email'),
KEY ('email', 'pass')

Should be (notice the back-ticks):

PRIMARY KEY (`id`),
UNIQUE KEY (`email`),
KEY (`email`, `password`)

Note also that your index is referring to a non-existent column pass - I've changed it to the correct column password.

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

Comments

1

You gone mad with the backticks

default '',

Two single quotes is empty string BackTicks are for column names and such e.g.

My Strange column name

2 Comments

Edited. Please check the description again!
So you fixed the backticks round the defaults, but you now have single quotes round the field names isn your keys as mentioned by @Perception. Strings are single quotes, objects (columns , tables etc) are backticks.

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.