php - #CodeIgniter Sending each "checked" check box values from multiple checkboxes to the database? -
i have populated check boxes database follows...
view:
<div class="control-group warning"> <label for="room_number" class="control-label">room number: </label> <div class="controls"> <?php foreach ($query->result_array() $row): { ?> <input type="checkbox" name="room_number" id="room_number" value="<?php echo $row['room_number'];?>" style="margin:10px" /><?php echo $row['room_number'];?><br> <?php } ?> <?php endforeach; ?> <?php echo form_error('room_number'); ?> </div> </div>
*now when user submits form, need populate database table, each row "checked" checkbox. however, code/ method below submits single row.*
controller:
foreach($this->input->post('room_number') $rm){ // 118 $newreservation = array ( 'guest_id' => $guest_id, 'room_number' => $this->input->post('room_number'), 'room_type' => $this->input->post('room_type'), 'meal_type' => $this->input->post('meal_type'), 'extra_beds' => $this->input->post('ext_beds'), 'purchases' => 0, 'guest_count' => $this->input->post('number_of_guests'), 'checkin' => $this->input->post('start_date'), 'checkout' => $this->input->post('end_date'), 'duration' => $this->input->post('reservation_duration'), 'total' => $this->input->post('total'), 'guest_status' => $this->input->post('guest_status'), 'payment_status' => 'pending', 'travel_agent' => $token, 'time_stamp' => $now ); $this->group_reservations_model->populate_new_reservations_table($newreservation);
model:
function populate_new_reservations_table($newreservation) { $this->db->trans_begin(); $this->db->insert_batch('reservations', $newreservation); if ($this->db->trans_status() === false) { $this->db->trans_rollback(); return false; } else { $this->db->trans_commit(); return true; } }
it returns following error:
a php error encountered
severity: warning
message: invalid argument supplied foreach()
filename: controllers/group_reservations.php
line number: 118
you have multiple checkboxes same name. use name="room_number[]"
istead of name="room_number"
.
good luck ;)
Comments
Post a Comment