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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

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

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

thanks

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Yes.

Code: Select all

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