View Full Version : Radio Button Form

06-10-2006, 12:32 AM
Hi there
Say you have a form with 3 options as follows:

1. Apples ()
2. Oranges ()
3. Pears ()

and you want the user to check one of the three options. For example, if apples is checked off, and then they check oranges, apples unchecks automatically and oranges appears checked off. In HTML this is a Radio button list...

How would you set up the table in the database to accept the option chosen?

Would it be ENUM ('Yes','No') and then ask PHP to put YES on the chosen field in the DB and NO in the 2 others?


06-10-2006, 12:42 AM
Surely one field in the database where you insert a value based on the option chosen is the easiest way. After all that's what you get passed from the form with the radio buttons.

06-10-2006, 12:54 AM
Oh I see... So I don't have to set up 3 frields? I just call the field "fruit" and then pass on the chosen fruit into that field?

Any help on how that would look like in MySQL codE?


06-10-2006, 03:34 AM
I use the ENUM Data Type & the code below. What ever you have set for the Value for the each button is the data that is entered into the db.
This is the Radio buttons

<input name="fruit_types" type="radio" value="Apples">
<input name="fruit_types" type="radio" value="Oranges">
<input name="fruit_types" type="radio" value="Pears">

This is the php code to insert into the db

$fruit_type = $_POST['fruit_types'];

$sql = mysql_query("INSERT INTO table (fruit) VALUES('$fruit_type')")
or die (mysql_error());

06-10-2006, 05:12 AM
Thanks Lansing
I'll use that to code the page... I meant though, in the table, in my database, how do I create that field? Is it just ENUM with no values and wait until the form passes the value?

06-10-2006, 06:23 AM

When you go to set up the table. Just enter the following into the Length/Values field & you must include the single quotes & comma's:

06-11-2006, 02:09 AM
thanks for the help! Let me give this a whirl and see how it works.

I appreciate your time spent on this.