Radio buttons from html form and setting corresponding Enums in mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lazairus
    New Member
    • Mar 2008
    • 3

    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_membersh ip 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_l ink $cols " .
    "VALUES $values";
    $result = mysql_query($sq l)
    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 "
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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_b utton, 0, strpos($radio_b utton, ' '));
    if (array_key_exis ts($number, $array))
    $enum_value=$ar ray[$number];
    echo $enum_value;
    ?>[/php]You can adapt the array to hold more values.

    Ronald

    Comment

    Working...