Hi, - I have a specific way I setup a list of options for a drop down menu for a database.
When the data inputs, it inserts the number (value) into the database. I am trying to do the opposite and have the actual name of the field inserted into the database table instead.
This is the line of code to set the variable for the field ethnic_id:
$ethnic_id = isset($_POST['ethnic_id']) && is_numeric($_POST['ethnic_id']) ? (int) $_POST['ethnic_id'] : 0;
This is the form code:
<select name="ethnic_id">
<option>-- Please Select --</option>
<?php foreach (get_ethnicity() as $ethnic) { ?>
<option value="<?php echo $ethnic['ethnic_id']; ?>"><?php echo $ethnic['ethnic_name']; ?></option>
<?php } ?>
</select>
This is where how I install the fields in the install.php (I do this so I can add to the list if need be for future preference)
echo 'Creating ' . $config['db']['prefix'] . 'ethnicity...<br />';
$db->query("DROP TABLE IF EXISTS " . $config['db']['prefix'] . "ethnicity");
$db->query("CREATE TABLE " . $config['db']['prefix'] . "ethnicity (
`ethnic_id` mediumint(6) NOT NULL auto_increment,
`ethnic_name` varchar(64) NOT NULL,
PRIMARY KEY (`ethnic_id`)
) TYPE=MyISAM ");
echo 'Inserting data into ' . $config['db']['prefix'] . 'ethnicity...<br />';
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('African');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Bangladeshi');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Caribbean');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Chinese');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Indian');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Pakistan');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White Caucasion');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White & Asian');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White & Black African');");
$db->query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White & Black Caribbean');");
If anyone has a suggestion I would really appreciate it. Cheers
Paul