Web Hosting Talk







View Full Version : sql table code giving unknown error


latheesan
06-30-2005, 04:24 PM
hi everyone,

i was just trying to create these tables and i keep getting error message saying

#1067 - Invalid default value for 'id'

this is the sql code im trying to run

CREATE TABLE users(

id int( 10 ) DEFAULT '0' NOT NULL AUTO_INCREMENT ,
username varchar( 40 ) ,
PASSWORD varchar( 50 ) ,
regdate varchar( 20 ) ,
email varchar( 100 ) ,
website varchar( 150 ) ,
location varchar( 150 ) ,
show_email int( 2 ) DEFAULT '0',
last_login varchar( 20 ) ,
PRIMARY KEY ( id )
)

So, where exactly im i going wrong?

RobertMaltby
06-30-2005, 04:51 PM
I may be wrong, but give this a try:

Make sure you are connected to your DB..
$result = "CREATE TABLE users
(
id INT(10) DEFAULT '0' AUTO_INCREMENT,
username VARCHAR(40),
PASSWORD VARCHAR(50),
regdate VARCHAR(20),
email VARCHAR(100),
website VARCHAR(150),
location VARCHAR(150),
show_email int(2) DEFAULT '0',
last_login VARCHAR(20),
PRIMARY KEY (id)
)";
$query = $mysql_query($result) or die(mysql_error());

Then on your page or script just call upon $query

As for you row "id" you wouldnt really need to say "not null" since basically you are giving the person / object an id # when you add them 'auto_increment'

Good Luck :P

hiryuu
06-30-2005, 04:57 PM
A default value is nonsensical on an auto-increment field with a unique key. Just this will be fine:
id int( 10 ) NOT NULL AUTO_INCREMENT

latheesan
06-30-2005, 07:16 PM
Originally posted by hiryuu
A default value is nonsensical on an auto-increment field with a unique key. Just this will be fine:
id int( 10 ) NOT NULL AUTO_INCREMENT

the above suggestion worked great. Thank you very much.

Also, platinumn23, thank you too. But sorry i couldnt try your method, as i lack knowledge of mysql.

tc, bye :)