Complex PHP Registration Form - Help needed please

Hi Guys,

New here and have tried searching but can’t seem to find what I’m after.

Basically I want to create a registration form for a website using PHP and MySQL. The form needs to have all the standard fields like:

Username
Password
Name
DOB
Email

But I also want to have a couple of extra questions in the form, these are:

Gender - Now am I right in thinking I should use ENUM for this with the values (‘m’,‘f’) ??

My next two are the ones that I’m totally stuck on, I want to have one question in the form that has a drop down box as the choices, for example:

Q. How often to you exercise?
Then the answers: 1 a week, 2 week, 3 a week, 4 or more a week

The other one is I’d like to have check boxes as the possible answers.

Now, I’m struggling to figure out where to go here, I have my page built with PHP and the form inside it, and I’m happy to build the table in MySQL but I don’t know what to set the values for those two answer categories as? Am I right in thinking that the answers need to be selected from a different pre-built table with the choices defined? If so, how do I do so and then save the selected choices in the “users” table that will store the data for my new registered user?

I hope I’ve made sense?

Many thanks in advance guys!

Welcome to SitePoint!

The question I’m going to ask to better answer you is this;

What do you want to be able to DO with the data?

Hi StarLion,

Thanks for replying!

Ok, so for the one that is (in my head) a drop down selector, once the data has been submitted by the user and they’ve registered. I essentially want to be able to run queries and select only the users who chose “2 a week” or run a query that selects only the people that chose “5 or more” etc

Does that make sense?

I guess I’m just wanting to know how the best way to use PHP and MySQL to record information selected from a drop down box, into my “users” table so that I can in future, run queries based on their responses.

I hope I’m making sense!

Thanks again.

If you expect to have multiple selections for the checkox question I would recommend keeping the values in an array, receive that array on the other end and loop through it to save into your database…

I don’t understand why you want to provide check boxes for a question that can only have 1 answer. Surely, radio buttons or a drop-down would be preferable. Unless I’ve got the wrong end of the stick??

Hi, sorry - yes that’s the one that I want for a drop down but am struggling to know how to do it??

The one with check boxes I’d like to have a choice of answers for example favourite sports and they then select from a list by putting a check in the box.

But it’s the drop down with the exercise habits that I’m really stuck on.

Thanks,

Is this what you mean? The selected value will be parsed with the rest of your form data:

  <select name="exercise_habits">
  <option value="Once a week">Once a week</option>
  <option value="Twice a week">Twice a week</option>
  <option value="Three times a week">Three times a week</option>
  <option value="Four or more times a week">Four or more times a week</option>
  </select>

or… you could just give the values as 1,2,3,4 and not parse them other than to check if they’re an INT :stuck_out_tongue: