View Full Version : Radio Button Form
06-09-2006, 11:32 PM
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-09-2006, 11:42 PM
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-09-2006, 11:54 PM
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, 02: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, 04:12 AM
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, 05: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, 01:09 AM
thanks for the help! Let me give this a whirl and see how it works.
I appreciate your time spent on this.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.