Help with a 6 line SQL CODE...

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
Uri
Forum Newbie
Posts: 3
Joined: Sun Oct 31, 2004 10:07 am

Help with a 6 line SQL CODE...

Post by Uri »

Hi all!
I'm not a newbie in PHP, altough I'm a newbie here...
I'm 13 years old.
I started learning PHP 6 months ago and now, after reading
1000+ about it and experiencing it I have a bitti problem.

I am familiar with MySQL only that I never experienced writing
on my own SQL code...1
OK enough about me.

Here is my problem:

Code: Select all

CREATE TABLE events_megamot(
eID INT UNSIGNED NOT NULL AUTO_INCREMENT,
event VARCHAR(200) NOT NULL,
by VARCHAR(25) NOT NULL,
date DATE NOT NULL,
PRIMARY KEY (eID)
);
I'm getting an error:

Code: Select all

#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 'by VARCHAR(25) NOT NULL,
date DATE NOT NULL,
PRIMARY KEY (eID
My server started using phpMyAdmin 2.6.0 does it has something to do
with it?

Thank you all geniuses!

Uri.
swdev
Forum Commoner
Posts: 59
Joined: Mon Oct 25, 2004 8:04 am

Post by swdev »

by is a reserved MySQL word, so you can't use it for the name of a column. Use another name.

http://dev.mysql.com/doc/mysql/en/Reserved_words.html
Uri
Forum Newbie
Posts: 3
Joined: Sun Oct 31, 2004 10:07 am

Post by Uri »

Woops!
Found it!
After almost breaking my head I must thank phpMyAdmin for thier colors
in SQL. I saw that the word "by" is in purple as the data type(VARCHAR, DATE, INT ect.).
I didn't know "by" is a datatype - what does it do?

P.S
-----
Thanks swdev didn't saw that.
swdev
Forum Commoner
Posts: 59
Joined: Mon Oct 25, 2004 8:04 am

Post by swdev »

by is not a datatype. It is a reserved word. It is used in clauses such as GROUP BY and ORDER BY[/big_search]
Uri
Forum Newbie
Posts: 3
Joined: Sun Oct 31, 2004 10:07 am

Post by Uri »

swdev wrote:by is not a datatype. It is a reserved word. It is used in clauses such as GROUP BY and ORDER BY[/big_search]
Oh right!
Post Reply