tags:

views:

43

answers:

2

HI

i want to insert data using form in CI but i am facing the problem

Here is my model code

function add_form()
    {
        $this->load->database();
        $id = $this->input->post('id');
        $name = $this->input->post('name');
        $age = $this->input->post('age');       
        $data = array(
        'name' => $this->input->post('name'),
        'age' => $this->input->post('age'),
        );
        $this->db->insert('user',$data);

    }

Here is my controller code

function simpleform()
{
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('welcomedb_model');
if($this->input->post('submit')){
 $this->welcomedb_model->add_form();
}
$this->load->view('welcomedb_view');

}

and here is my view code

<?php echo form_open('welcomedb/submit'); ?>
<? echo $name; ?>: 
<? echo form_input('name'); ?>
</br>
<? echo $age; ?>: 
<? echo form_input('age'); ?>
</br>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>

Thanks for your help

+2  A: 

Your form is submitting to welcomedb/submit, but your controller appears to be at welcomedb/simpleform... maybe you need to change that.

Otherwise, there doesn't appear to be anything wrong.

bschaeffer
i did but its not working
vipinsahu
Finally i found the solution it should be <?php echo form_open('welcomedb/simpleform'); ?> Thanks for help
vipinsahu
A: 

probably $data = array( 'name' => $this->input->post('name'), 'age' => $this->input->post('age'), ); remove comman from age like $data = array( 'name' => $this->input->post('name'), 'age' => $this->input->post('age') ); and always dump error.