views:

89

answers:

5

i have users and i need them to specify a gender (male, female) and year of birth (1930, 1931...1999, 2000).

i wonder where i should store these values:

  1. in the database?
  2. in php file?

if i store them in the database i have to manually create all entries first. but a good thing is that the user table will have constraints so the gender field will always be male or female, it cannot be something else.

if i store them in the php file (eg. as html) then i can easily add/remove values. but a con is that i dont have the constraints in database, so another value could be stored as gender by mistake, even though i could add validation in php backend so even if someone hacked the html it is not stored unless it's either male or female.

what is best practice to do this?

thanks

+1  A: 

Go with a database as you'll no doubt want to query records later and working with HTML (or text files) for this type of thing would be a pain. As Dave said a little upfront work saves your bacon later!

Alistair
Hmmmmm baaaacooooooooo
Ben
+1  A: 

I would definitely go with a database, as that is the main point of a database, to house data. You can, as you said add restraints, expand collected data (i.e. addresses, phone numbers, user likes/dislikes), and search/query for data much easier with a database. As for the initial entry, there are many ways of getting data into a database with sql. There may be a very simple way of getting your current users into the database without too much work.

__nv__
A: 

If I understand right you need to store the 1997, 1998, 1999, etc... 'Male', 'Female' values, NOT the complete user row. If is in that way I think the best solution is store it in a external file, like ini, xml, php (array), etc...

A excelent choice is generate that file from the database metadata. For example, if you have a enum field ENUM('Male', 'Female') then you generate the options in that way. Actually you can generate the default input size, number or date validators, etc...

I think the best solution is separate the backend datastore from the view. What if you need to translate the page so you need to show 'Masculino' instead of 'Male' but remains in the database the value 'Male'?

Mahomedalid
+1  A: 

What format is your data in now? Chances are you will be able to automatically insert it into the database. Should be some good classes on phpclasses.org that will help. Would defiantly be worth installing phpMyAdmin on your server (or you might already have it). Makes working with databases so much easier.

Olly Hicks
+1  A: 

use a database, easy call...

Navicat is the bomb when it comes to a gui if you are looking for that sort of deal.

David Morrow