FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP/MySql database (Ver. 5)





mringuk
I am trying to set up a Members Databas using phpMyAdmin but I keep getting an error. Here is the code followed by the returned error. Any advice would be most welcome.

CREATE TABLE `web47-members-3`.`members` (
`id` INT NOT NULL AUTO_INCREMENT ,
`first_name` VARCHAR( 25 ) NOT NULL DEFAULT '',
`last_name` VARCHAR( 25 ) NOT NULL DEFAULT '',
`email` VARCHAR( 50 ) NOT NULL DEFAULT '',
`username` VARCHAR( 25 ) NOT NULL DEFAULT '',
`password` VARCHAR( 25 ) NOT NULL DEFAULT '',
`activated` ENUM NOT NULL DEFAULT '0',
`date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY ( `id` ) ,
UNIQUE (
`id` ,
`email` ,
`username`
)
) ENGINE = MYISAM ;


MySQL said: Documentation
#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 'NOT NULL DEFAULT '0', `date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', ' at line 1



Mike
rvec
remove the '' around the 0
numbers shouldn't be passed as strings
mringuk
I didn't place the '' around the Zero, phpMySql did that.
jmraker
You need to enter the values to enumerate like 'red', 'blue', 'green', 'yellow'. and the default if it's not the first one.

where it generates
Code:
ENUM('red', 'blue', 'green', 'yellow') NOT NULL DEFAULT 'green',


http://dev.mysql.com/doc/refman/5.0/en/enum.html
mringuk
I'm getting a little dishartened with this as I'm using the phpMySql system to set up this database but even the above corrections, the errors persist and the database fails to be created.
jmraker
If the error is the same, you can try simplifying the create table command by removing the field(s) you think are causing the error. You can then go back an add the field(s) to the table.

The error text usually indicate where the syntax error is located.

where your original error is between "ENUM" and "NOT NULL".

If you can't get phpMyAdmin's create/modify table forms to work you can copy what it came up with and paste it into the "sql" tab to edit until it works.
kv
There is an error in the syntax of ENUM. You should specify a list of values for enum like

Code:
ENUM ('1', '2', '3')


or something like that

For more details refer http://dev.mysql.com/doc/refman/5.0/en/enum.html
mringuk
I've put it together without the line
`activated` ENUM NOT NULL DEFAULT '1, 2, 3',
and it works fine. I've tried everything with the 'activated line, numbers & colours, but no luck.
rvec
`activated` ENUM('1', '2', '3') NOT NULL,
That doesn't work?
jmraker
You can try changing the ' with " as in enum("a","b","c")
In the mysql world there's 3 quotes, the ` (grave accent), ' (apostrophe), and " (double quote)

As far as I know the first one is only for field/table names and there's a syntax error if it's used wrong.

You can also try removing the NOT NULL part
mringuk
CRACKED IT NOW

THANKS ALL
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.