Post your trick

Inserting multiple values from a listbox into the database

if you have a listbox called “department” and want to insert multiple values from the listbox into the database,then:
when the user submits the form,store the value in a variable
$company_dept=$_POST['department'];
query:INSERT into table_name values(’”.join(”,”,$company_dept).”‘)


4 Responses to “Inserting multiple values from a listbox into the database”
  • jimit March 15th, 2010 at 3:06 pm

    hi dharmesh,
    i was unable to understand your trick can you please explain


  • dharmesh22 March 16th, 2010 at 5:41 am

    well wen i was new to this programming world i came across a problem while doin a project…
    i had a simple form…which had some text feilds,radio buttons and one listbox..on clickin d submit button..all d values should into the DB..
    so my listbox..contained 5 values..say for example
    listbox name is departmnt n its includes I.T ,H.R , Finance, Marketing ,Sales.so suppose if i select all 5 values..den all 5 should go into the DB inside a single column…n i achieved it by using d above code…can u plz suggest a better method..or the method which i hav used is ryt ?


  • jimy March 16th, 2010 at 9:32 am

    hi dharmesh,

    i understood what u were need to do but the method you are using will make repeating value in the database may i can suggest u one method by which u can eliminate repeating value by assigning id to every department and store only ids separated by comma (,) instead of storing full names of the departments one more advantage is there that u can keep departments spellings dynamic


  • dharmesh22 March 17th, 2010 at 5:44 am

    Thanx a lot !!!

    Dharmesh


Leave a Reply

     

     

     

Post A Trick !

How does "Kodetricks" work?

We at kodeplay like to share knowledge. With Kodetricks, even you can join us. All you need to do is post a programming related trick if you have one or rate a trick if you like someone else's.



Find us on

Technology

Contact Us