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.