Welcome Guest, Not a member yet? Register   Sign In
how to insert data into a table
#1

[eluser]Unknown[/eluser]
actually am done already this
but now no records were inserted in my table
why this happened?
i'l send the controler code
pls give me the suggestions
thanq


Code:
<?php

class Welcomenote extends Controller {

        
    
    function index()
    {

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('firstname', 'Firstname', 'trim|required');
        $this->form_validation->set_rules('lastname', 'Lastname', 'trim|required');        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[confirm_password]|md5');
        $this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');                
        $this->form_validation->set_rules('phonenumber', 'Phone Number', 'trim|required|numeric');                

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('welcome_view');
        }
        else
        {
            $this->load->view('success_view');
        }
    }
    
    function form_insert()    
            {
            $this->db->insert('registrationform',$_POST);
            }    
}

?>
#2

[eluser]Unknown[/eluser]
[quote author="sarram" date="1252089323"]

Code:
<?php

class Welcomenote extends Controller {

        
    
    function index()
    {

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('firstname', 'Firstname', 'trim|required');
        $this->form_validation->set_rules('lastname', 'Lastname', 'trim|required');        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[confirm_password]|md5');
        $this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');                
        $this->form_validation->set_rules('phonenumber', 'Phone Number', 'trim|required|numeric');                

       ?>
[/quote]

Code:
class Welcomenote extends Controller {
   function index()
    {

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('firstname', 'Firstname', 'trim|required');
        $this->form_validation->set_rules('lastname', 'Lastname', 'trim|required');        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[confirm_password]|md5');
        $this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');                
        $this->form_validation->set_rules('phonenumber', 'Phone Number', 'trim|required|numeric');                

        $this->form_validation->set_rules($config_validation);
        if ($this->form_validation->run()){
               $dtInsert = array(
                    'firstname' => $this->input->post('firstname'),
                    'lastname' => $this->input->post('lastname'),
                    'username' => $this->input->post('username'),
                    'password' => $this->input->post('password'),
                    'confirm_password' => $this->input->post('confirm_password'),
                    'email' => $this->input->post('email'),
                    'phonenumber' => $this->input->post('phonenumber'),
                    );
                    if($this->model_name->add($dtInsert)){
                        // your input success message or redirect
                    }    
        }
    }
  
}
#3

[eluser]Jay Logan[/eluser]
Don't really like running database queries in the controller but if you insist.........

Code:
<?php

class Welcomenote extends Controller {

        
    
    function index()
    {

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('firstname', 'Firstname', 'trim|required');
        $this->form_validation->set_rules('lastname', 'Lastname', 'trim|required');        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[confirm_password]|md5');
        $this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');                
        $this->form_validation->set_rules('phonenumber', 'Phone Number', 'trim|required|numeric');                

        if ($this->form_validation->run() == FALSE) {

            $this->load->view('welcome_view');

        } else {
            
            $post_data = $_POST;
            unset($post_data['submit']);
            $this->db->insert('registrationform', $post_data);
            $this->load->view('success_view');

        }
    }
    
}

?>




Theme © iAndrew 2016 - Forum software by © MyBB