English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

Standard Twin

Standard Queen\

Family
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

2006-08-14 22:11:05 · 2 answers · asked by 183 1 in Computers & Internet Programming & Design

if(!isset($_POST['room_type_id']))
{
//array is empty
$_POST['room_type_id'] = array();
echo "None selected.";
}
else
{
//must do this for checkboxes (passing multiple values)
foreach ($_POST['room_type_id'] as $items)


{

echo $items;
}
}
when i echo to see the result, i get :112 and then value in field roomtype_id (table bookdetail) will only store the value "2".Where is another two value "1" store?Can anybody help me solve this problem?I'm new in php.Pls help.... i have try to search this problem since last week, but untill now i cant find a solution.Pls help.... thank you :(

2006-08-14 22:30:14 · update #1

2 answers

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.

2006-08-14 22:21:34 · answer #1 · answered by thomasalanshearer 2 · 0 0

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.

2006-08-15 09:08:29 · answer #2 · answered by AnalProgrammer 7 · 0 0

fedest.com, questions and answers