types?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

types?

Post by method_man »

hi, im making a register page and i would like to know what i should put the different things the user submits into my database.

for example:

these are the things the user submits

First Name: (should this be Char or VarChar or another one?)
Last Name: (same as first name)

Password: (no clue)
Confirm Password: (no clue)

Email Address: (same as first name)
Confirm Email Address:(same as first name)

Sex: (what should this be if its a drop down bar thing?)

Date of Birth: (should this be date time or time stamp or another one? and how can i make it so the user has to imput it as mm/dd/yyyy?)

City: (same as first name)

Country: (same as sex)

thanks for the help,

matt
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

1st question: Why on earth would you want to save *-confirm fields in the database?


Types:

First Name: varchar (50)
Last Name: varchar (75)

Password: varchar (32) if you want MD5 encryption, varchar (40) for SHA1 [for any other encryption use appropriate size]
Confirm Password: [forget about this column]

Email Address: varchar (100)
Confirm Email Address: [forget about this column]

Sex: int (1) [an int with size 1 which can be used as a boolean or for values 0,1,2 equalling undisclosed, male, female for instance]

Date of Birth: int (10) [standard Unix Timestamp]

City: varchar (150) [just to be sure of extra long names]

Country: enum, int (3) or other depending on implementation

For info on the types, check the MySQL Manual.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I agree on the most part, but a CHAR (1) would be better for Sex, then it could be M or F.

Also, a DATETIME (or similar date storage type if time is irrelevant - which it probably will be with a DOB) would be better than a VARCHAR (10) for the DOB.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

jayshields wrote:I agree on the most part, but a CHAR (1) would be better for Sex, then it could be M or F.
Matter of taste, I guess. I'd use an int because it's more comfortable somehow. :wink:
jayshields wrote:Also, a DATETIME (or similar date storage type if time is irrelevant - which it probably will be with a DOB) would be better than a VARCHAR (10) for the DOB.
Agreed, was thinking of dates in general.
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

thanks :D
Post Reply