1

Everything is working fine except, instead of writing the data on the form, it writes zeros. The table (new_reservation) looks like this after submitting some values:

enter image description here

PK: res_id (AI, NN)

Not Null: All except "ext_bed"

Model: (reservations_model.php)

class Reservations_model extends CI_Model {

function add_reservations($data) {
    $this->db->insert('new_reservation', $data);
    return;
}

}

Controller: (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();
}
}

View: (new_reservation.php in /views/main folder)

<?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(); ?>
0

4 Answers 4

2

In view

Use name not id

sample example from your code

<p>      
<label for="start_date">Check-in Date*: </label>
<input  type="text" id="start_date" name="start_date" />
</p>
Sign up to request clarification or add additional context in comments.

Comments

1

Your form data.. they should have a name value ex:

<input type="text" id="end_date" name="end_data"/>

Comments

1

Use name along with id, eg:

<input type="text" id="number_of_guests" name="number_of_guests">

for all the input statements

Comments

0

get a value using name not by id

<input type="text" id="number_of_guests" name="number_of_guests">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.