sandesh phuyal sandesh phuyal - 5 months ago 46
PHP Question

Codeigniter submit not working

Error
Submit button from the view does not pass the value.

After submit button is clicked, then pass value from view to controller, then to the model. Database structure consists of table(booking) and column name ( booked_id, name and mobile) . But the value is not passed to the controller neither to the database.

View

<form method="post" action="">
<input type="text" value="<?php echo isset($post)?$post->name:''; ?>" name="manakamana[name]"/>
<input type="text" value="<?php echo isset($post)?$post->mobile:''; ?>" name="manakamana[mobile]"/>
<button type="submit" class="btn btn-success">POST</button>
</form>


Controller

public function bookManakamana(){

if ($data = $this->input->post('manakamana')) {
$data['created_on'] = date('Y-m-d H:i:s');
$this->booking->add($data);
redirect('booking');
} else {
$this->load->view('index');
}

}


Model

function add($data)
{
$this->db->insert('booking', $data);
}

Answer

Form action is not given

<form method="post" action="<?php echo base_url().'controller name/function name' ?>">
<input type="text" value="<?php echo isset($post)?$post->name:''; ?>" name="name"/>
<input type="text" value="<?php echo isset($post)?$post->mobile:''; ?>" name="mobile"/>
<button type="submit" class="btn btn-success">POST</button>

in controller

public function bookManakamana(){
if ($this->input->post('name')) {
    $data['created_on'] = date('Y-m-d H:i:s');
    $data['name'] = $this->input->post('name');
    $data['mobile'] = $this->input->post('mobile');
    $this->booking_models->add($data); //booking_model is the name of model
    redirect('booking');
} else {
    $this->load->view('index');
}}