フォームにデータを書き込む代わりに、ゼロを書き込むことを除いて、すべてが正常に機能しています。いくつかの値を送信すると、テーブル (new_reservation) は次のようになります。
PK: res_id (AI、NN)
Null 以外: 「ext_bed」以外のすべて
モデル: (reservations_model.php)
class Reservations_model extends CI_Model {
function add_reservations($data) {
$this->db->insert('new_reservation', $data);
return;
}
}
コントローラー: (reservations.php)
class Reservations extends CI_Controller {
function index() {
$this->load->view('/main/new_reservation');
$this->load->model('reservations_model');
}
function add_reservations() {
$data = array (
'room_type' => $this->input->post('room_type'),
'meal_type' => $this->input->post('meal_type'),
'bed_type' => $this->input->post('bed_type'),
'ext_beds' => $this->input->post('ext_beds'),
'number_of_guests' => $this->input->post('number_of_guests'),
'start_date' => $this->input->post('start_date'),
'end_date' => $this->input->post('end_date'),
'reservation_duration' => $this->input->post('reservation_duration'),
'room_number' => $this->input->post('room_number'),
'total' => $this->input->post('total')
);
$this->reservations_model->add_reservations($data);
$this->index();
}
}
ビュー: (/views/main フォルダー内の new_reservation.php)
<?php echo form_open('reservations/add_reservations'); ?>
<p>
<label for="room_type">Room Type*: </label>
<select id="room_type"></select>
</p>
<p>
<label for="meal_type">Meal Type*: </label>
<select size="1" multiple="multiple" id="meal_type"></select>
</p>
<p>
<label for="bed_type">Bed Type*: </label>
<select id="bed_type"></select>
</p>
<p>
<label for="ext_beds">Extra Bed(s): </label>
<input type="text" id="ext_beds" />
</p>
<p>
<label for="number_of_guests">Number of Guests: </label>
<input type="text" id="number_of_guests" />
</p>
<p>
<label for="start_date">Check-in Date*: </label>
<input type="text" id="start_date" />
</p>
<p>
<label for="end_date">Checkout Date*: </label>
<input type="text" id="end_date" />
</p>
<p>
<label for="reservation_duration">Duration: </label>
<input type="text" id="reservation_duration" />(Nights)
</p>
<p>
<label for="room_number">Room Number: </label>
<input type="text" id="room_number" />
</p>
<p>
<label for="total">Total: </label>
<input type="text" disabled="disabled" id="total" readonly="readonly" />
</p>
<p>
<input class="btn" type="reset" />
<input class="btn btn-primary" type="submit" value="Check-in" />
</p>
<?php echo form_close(); ?>