By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

Radio buttons from html form and setting corresponding Enums in mysql

P: 3
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
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
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

Post your reply

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