Page 1 of 1

how to insert values from a combo box to a database??

Posted: Mon May 09, 2005 9:34 am
by ant_sutton
Hi guys. I really need so help with this if you can please.

I have a combo box with the value 'ISB001- team projects'. When this is selected, and submitted I want to insert only the code part - 'ISb001' into a 'module' table of my sql database. Is there any way to insert just the code and not the course title part of this combo box entry?

Thanks in advance

Ant

Posted: Mon May 09, 2005 9:39 am
by anjanesh
1. You can use substr($optVariable,0,6) to return ISB001
2. Better still use <option value="ISB001">ISB001- team projects</option> in your HTML code instead of
<option>ISB001- team projects</option> which will return the name (ISB001- team projects) as the value.

thanks

Posted: Mon May 09, 2005 9:59 am
by ant_sutton
Hi. Thanks for your quick reply I'm actually taking the code ISB001 from the modulecode field of the table and course title from the title field. I am then looping round and inserting them into the combo box. Would the 'select value' still work, or is there another way to do this?

Anthony

Posted: Mon May 09, 2005 10:12 am
by anjanesh
Yes.

Code: Select all

$row = mysql_fetch_array($result);
loop 
 {
 echo '
 <option value="'.$row['modulecode'].'">'.
 $row['modulecode'].' - '.$row['title'].'
 </option>
 ';
 }