Page 1 of 1

Foreign key

Posted: Fri Dec 25, 2009 5:55 am
by dwsddas
Hi, I have a code to create two tables. And the code does not work. Can you tell me where is wrong. I think that I need to do something with INDEX.

Code: Select all

 
 
mysql_query("CREATE TABLE users 
                    (username varchar(15),
                                PRIMARY KEY (username),
                    lastname text,
                    firstname text,
                    password text)
                    ENGINE=INNODB;
                    ")
 
                    mysql_query("CREATE TABLE textt 
                    (username varchar(15), 
                    textname text,
                    textbody text,
                    INDEX (username),
                    FOREIGN KEY (username) REFERENCES users(username))
                            ENGINE=INNODB;
                    ")

Re: Foreign key

Posted: Fri Dec 25, 2009 6:32 am
by VladSun
Try
[sql]INDEX IX_username (username)[/sql]

Re: Foreign key

Posted: Fri Dec 25, 2009 7:18 am
by dwsddas
Doesn't work. It shows error message:

Parse error: syntax error, unexpected T_STRING in /home/...

Re: Foreign key

Posted: Fri Dec 25, 2009 9:32 am
by Weirdan
You missed semicolons after mysql_query() function calls. It has nothing to do with index or database.