Page 1 of 1

Use of SET (and ENUM) MySQL data types

Posted: Wed Aug 13, 2003 2:18 am
by Keith_Wilkinson
I'm just after an example of how to use the SET and ENUM
data types with forms. As an example of such a form:

- - - - - - - - -

I am primarily a:
(o) Editor (o) Writer (o) Translator
specializing in
(*) General (*) Finance/economy (*) Medical (*) Patents/law

- - - - - - - - -

where (o) is a radio button and (*) is a checkbox.

This (the above) data entry form would
(1) Store selected check boxes as MySQL SET and
ENUM (bit) data (corresponding to check boxes
and radio buttons),
(2) In "Modify data entry form", mode display previously-
entered data (from database) as check box/radio button
form defaults,
(3) When SEND is clicked on form, display text labels of
checked checkboxes/radio buttons as confirmation
of data that has been sent.

Actually just (1) and (2) would be sufficient for
my purposes.

Posted: Wed Aug 13, 2003 8:44 am
by JAM
Well, perhaps this can give you some ideas?

Code: Select all

<?php
// somehow get the "I am a" value...
    $iamselection = mysql_result(mysql_query("select i_am_a from username"),0);
// ...and set a var with ' checked' to include later...
    if ($iamselection) { 
        $iamselection = ' checked';
    } else {
        $iamselection = ''
    }
// Do something similiar to the checkboxes...
?>
<pre>
<form method="post">
<input type="radio" name="iam" value="1"<?php echo $iamselection; ?>>Editor
<input type="radio" name="iam" value="2"<?php echo $iamselection; ?>>Writer
<input type="radio" name="iam" value="3"<?php echo $iamselection; ?>>Translator
<hr>
<input type="checkbox" name="spec[]" value="General">General
<input type="checkbox" name="spec[]" value="Finance">Finance
<input type="checkbox" name="spec[]" value="Medical">Medical
<input type="checkbox" name="spec[]" value="Patents">Patents
<input type="submit">
</form>

<?php
 // debug to see the results of submitting the form, and what you canuse.
    if (isset($_POST['iam'])) {
        echo $_POST['iam']."\n";
    }
    if (isset($_POST['spec'])) {
        print_r($_POST['spec']);
    }
?>
Note, that it's just an idea of approach. Tweaking it to your needs...