mercredi 15 juillet 2015

Updating database based on checkbox Codeigniter

I'm trying to update a database column using a checkbox. The idea is that I want to only display certain things on the homepage, so the checkbox should send either 0 or 1 to the DB. If the record has 0 in the first page column, it shouldn't appear on the homepage, if it has 1 it should appear.

I tried setting something up, but it doesn't work as intended (it just refreshes the page with no effect)

The checkbox:

<?php echo form_checkbox(array('name' => 'first_page', 'class'=>'checkbox-inline', 'value' => 1)); ?>

Controller:

if(null != ($this->input->post('first_page'))) {
    $first_page = 1;
    $book_id= $this->input->post('id'); (the id is sent to the controller via an extra hidden input field)

    $this->book_model->first_page($first_page, $book_id);
}

Model:

$this->db->set ( "first_page", $first_page);
$this->db->where ( "book_id", $book_id);
$this->db->update ( "books" );
return;




Aucun commentaire:

Enregistrer un commentaire