1

Hi newbie developer here, I'm currently working on a system where the user will first answer the registration form then the user will be directed to another page, but the problem is i cant insert data in the data using codeigniter 3. Here is my controller:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Register extends CI_Controller {
    
    
    public function index(){
    

        if(isset($_POST['register'])){
            $this->form_validation->set_rules('fname', 'First Name', 'trim|required');
            $this->form_validation->set_rules('lname', 'Last Name', 'trim|required');
            $this->form_validation->set_rules('email', 'Business e-mail ', 'trim|required|isUnique');
            $this->form_validation->set_rules('contact_number', 'Mobile Number', 'trim|required');
            $this->form_validation->set_rules('organization', 'Organization', 'trim|required');
            $this->form_validation->set_rules('designation', 'designation', 'trim|required');


            if($this->form_validation->run() == TRUE){
                 echo "form validated";

                $data = array(
                    'fname' =>$_POST['fname'],
                    'lname' =>$_POST['lname'],
                    'email' =>$_POST['email'],
                    'contact_number' =>$_POST['contact_number'],
                    'organization' =>$_POST['organization'],
                    'designation' =>$_POST['designation'],
                );

                 $this->db->insert('register', $data);

                 $this->set_session->flashdata("success ");

            }
        }
        $this->load->view('register');

    }

    
    
    
}

    

    

?>

and here is my model:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

Class RegisterModel extends CI_Model {
    
    public function __construct()
    {
        parent::__construct();
        $this->load->model('RegisterModel'); 
        $this->load->database();
    }

   

}

?>

I'm a newbie at web developing. Thanks for answering.

vee
  • 4,506
  • 5
  • 44
  • 81
Vasco Wayne
  • 75
  • 1
  • 6
  • Can't insert data? What is the error message? Please [enable and show all errors](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1) message while in development and included it here in your question. – vee Dec 10 '21 at 04:39
  • there are no error message its just that when i view the database on xampp there is no data inserted – Vasco Wayne Dec 10 '21 at 05:42
  • Is it echo out _form validated_ correct? If yes, what is the result of `var_dump($data);exit();`? Codeigniter has `$this->input->post()` for use instead of `$_POST`, you should use that instead. See [reference/document](https://codeigniter.com/userguide3/libraries/input.html#CI_Input::post). – vee Dec 11 '21 at 04:22

0 Answers0