Getting the value from a select list box using php?

Hi,
I’m populating a select list from a mySQL database like so :-

<?
// Populate Type List Box with up to date Equipment Types
$sql = “SELECT * FROM types ORDER BY type ASC”;
// execute SQL query and get result
$sql_result = mysql_query($sql,$dbcnx)
or die(“Couldn’t execute query.”);
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$type = $row[“type”];
$typedesc =$row[“typedesc”];
$option_block .= “<OPTION value=\”$type\“>$typedesc</OPTION>”;
}
?>

<SELECT name=“selecttype” id=“selecttype”>
<? echo “$option_block”; ?>
</SELECT>

What i’d like to know is how i can set my field type = to the value of the selected item in the select list.

For example : i select the item ‘Electrical Motors’ from the list, the value of this is ‘ecm’ - i need to store that value in the field named type in mysql table.

I’m getting confused as i thought u get the value using Java Script and am not sure of the best way or when to break out of php and javascript etc.

Would i be right in saying it’s somthing like this :-

$type =?><script>document.theform.selecttype.value</script><?;

That doesn’t work obviously… but i’m trying

This is probably pretty simple, but i’d really appreciate it if someone could give me an example please?

Thanks in advance :slight_smile:

I’m trying to figure out, what you mean, but have no idea :rolleyes: :confused:

You’re reading your values from a database and wan’t to write back the selected item to the db?

Perhaps you can provide an other example. Blame it to my ignorance that i can’t follow you.

for any values from that select to be added/inserted into a db the form must be submitted.

so - just use $_POST[‘selecttype’];

other than that, try explaining better - maybe without bothering to show the select creating code and showing what’s on the receiving end.