How to Validate an Email Duplicate Entry in Codeigniter

// Step 1: Load the form validation library in your controller
$this->load->library('form_validation');

// Step 2: Set the validation rules for the email field in your controller
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');

// Step 3: Check if the form validation is successful
if ($this->form_validation->run() == FALSE) {
    // Validation failed, handle errors (e.g., display error messages)
    $this->load->view('your_form_view');
} else {
    // Validation passed, proceed with your logic to insert the data
    $data = array(
        'email' => $this->input->post('email'),
        // Add other fields as needed
    );

    // Your database insertion logic goes here
    $this->your_model->insert_user($data);

    // Redirect or show success message as needed
    redirect('success_page');
}

Make sure to replace 'users.email' with the actual table and field name in your database. Also, customize the controller, view, model names, and other details based on your application structure.