473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Radio buttons from html form and setting corresponding Enums in mysql

simply how do you set enums in a database using coorsoponding radio button from a html form

now i have a table client_membership in mysql

with the membership_type enum('six','one')

i have html corrosponding radio button
6 months
1 year

i have also a Sql insert ignore that insert text field values into the SQLdbase

i want to write a php script that takes the html radio buttons and sets the enum values in the mysql database


to make it even simpler, i have some code that is similiar
this was taken from the wrox book , Beginning apache mysql php .....2005

[PHP] <?php
if ($enemies != '') {
$val = "";
foreach ($enemies as $key => $id) {
$val[] = "('$charid', '$id')";
}
$values = implode(',', $val);
if ($align = 'good') {
$cols = '(good_id, bad_id)';
} else {
$cols = '(bad_id, good_id)';
}
$sql = "INSERT IGNORE INTO char_good_bad_link $cols " .
"VALUES $values";
$result = mysql_query($sql)
or die(mysql_error());
}
?>[/PHP]

(comic fan site)

Can you noble professional coders explain how to adapt this code
i have tried already and have an idea how it is done but fail at every attempt

Cheers
Lazairus.
"Cast a cold eye ,on Life , on Death , Horseman Pass bye
W.B Yeats "
Apr 2 '08 #1
1 3477
ronverdonk
4,258 Expert 4TB
Hope I understand the problem: you want to translate the 1 into one, and 6 into the word six. See this little routine[php]<?php
$array=array('1' => 'one', '6' => 'six');
$radio_button='1 year';
$number = substr($radio_button, 0, strpos($radio_button, ' '));
if (array_key_exists($number, $array))
$enum_value=$array[$number];
echo $enum_value;
?>[/php]You can adapt the array to hold more values.

Ronald
Apr 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: obsidian8 | last post by:
Hi All, I have looked around for an answer to this question, but haven't found one as of yet. I'm trying to use javascript to dynamically create raido buttons. I am able to create them easily...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
22
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I...
1
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
7
by: IchBin | last post by:
I am trying to programmatically set a radio button in a table of radio buttons. I have two problems with the code below: 1 - I can not prepare the <Formstatement to be printed by php. (syntax...
7
by: help4me | last post by:
Hope someone can help me out with this. I'm having trouble getting my radio button values into a MySQL database. And after I do get them inserted I'm going to want to be able to show them back in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.