Drop input database is numeric - need to change

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...&lt;br /&gt;';

$db-&gt;query("DROP TABLE IF EXISTS " . $config['db']['prefix'] . "ethnicity");
$db-&gt;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...&lt;br /&gt;';

$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('African');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Bangladeshi');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Caribbean');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Chinese');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Indian');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('Pakistan');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White Caucasion');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White & Asian');");
$db-&gt;query("INSERT INTO " . $config['db']['prefix'] . "ethnicity (ethnic_name) VALUES ('White & Black African');");
$db-&gt;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

A web browser will send the value attribute of an option element when the form is submitted. So, give them appropriate values.

<option value=“whatever you want”>

Yeah, I wish sometimes it was that simple … I tried that with country_name … and no joy… any other suggestions would be appreciatated :slight_smile:

It’s just a case rather than the value number being implemented, having the country name implemented … any suggestions much appreciated

Try this:



<select name="ethnic_id">
	<option>-- Please Select --</option>
	<?php foreach (get_ethnicity() as $ethnic) { ?>
	<option value="<?php echo $ethnic['ethnic_name']; ?>"><?php echo $ethnic['ethnic_name']; ?></option>
	<?php } ?>
</select>


I tried that :slight_smile: … I cocked something up in the install file, didn’t set the table correctly … all sorted now.

Thanks for the replies.