How to insert a multiple value into database but not a single column?
-
I have a table in my database (call roomtype) with the rows roomtype_id(Primary Key) and room_type. I have another table (call bookdetail) with the rows book_id, guest_ic and roomtype_id.I have a simple form that allow user check the checkbox which room they want to stay. <input type="checkbox" name="room_type_id[]" value="1" /> Standard Twin</label> <input type="checkbox" name="room_type_id[]" value="2" /> Standard Queen</label>\ <input type="checkbox" name="room_type_id[]" value="3" /> Family</label> after they check, will post it to another page.Did anybody know how to insert the value to the field roomtype_id in table bookdetail?Eg: book_id -----guest_ic--------------- roomtype_id 2 --------840116 -------------- 1 2 ---------840116 ------------- 1 2 ------------840116 -------------- 2 but my problem is the roomtype_id only store a last value:2 but the value 1 never store?Can anybody help?Pls
-
Answer:
Why don't you use a radio button instead of a checkbox? I presuem they can only stay in one type of room? If not.. and you do want to store multiple values u just need to interate through the room_type_id array which will be stored in the page you are posting the data to.. If you are using php.. print_r(room_type_id); this will print out your array so you can check that you have the correct values.. then for each value.. write a row to the database.. use the foreach php function.. check out the source below. . I think this should solve your problem.
thomasal... at Yahoo! Answers Visit the source
Other answers
Your check boxes need to be given a unique name like room_type_id_1 and room_type_id_2 etc. That should fix it.
AnalProgrammer
Related Q & A:
- How do you insert a picture on yahoo when you ask a question?Best solution by Yahoo! Answers
- How can I earn from working at home without spending a single penny?Best solution by Yahoo! Answers
- How good is a career as a Database Administrator?Best solution by Yahoo! Answers
- How to insert a picture into email?Best solution by Yahoo! Answers
- How to insert a date variable in java?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.