Creating basic PHP Survey?

  • Thread starter Thread starter chibuki
  • Start date Start date
C

chibuki

Guest
Haven't done this in a while, so I kinda lost the grasp of it with forms. Basically, I'm trying to do a short 10 question survey on a website that involves regular text boxes, drop down answers, and radio buttons.

Just to be sure, do I have to provide a field for each question? Plus the index and also the user's name of course.

Also I'm lost on how creating multiple choice questions using radio buttons. e.g.:
1. Are you male or female?
a) male
b) female

2. What is your status?
a) student
b) faculty
c) parent

How do I make it so that the answer submits to the right field in the database? All I need is just one form for the whole 10 questions right?

Thanks, any help will be appreciated.
 
Yes, you need a field for each question.

Multiple choice questions will just have the answers, each with the same "name" attribute in the input tag, but each one having a different value (i.e., "male", "female"). You can also choose which one you want selected by default using "checked" in the tag.

Yes, one form can be used for all the questions.

How they get submitted to the database is up to you. The form item names and the selected answers are handed back to the action script in a query. You have to create the code to take each response and drop it into the database field of your choice.
 
For the radio buttons, the name for the input should be the same for each segment, for instance:
1. Are you male or female?
<input type="radio" name="MorF" value="male">male
<input type="radio" name="MorF" value="female"> female

That way you can only select one OR the other, same with multiple choice. On the PHP page you submit to, draw the values using $_GET['formfieldname'] and use the PHP to insert it into the proper field in the database. I hope this helps, feel free to contact me with specific questions.
 
Back
Top