Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck duplicate data in CodeIgniter try to make a callback function
    primarykey
    data
    text
    <p>I have a registration form. Here I'm able to check duplicate email by my custom is unique call back function (Don't try to use is_unique). But it doesn't returns anything. Here is my code.</p> <p>Controller - </p> <pre><code>public function add_member () { $this-&gt;load-&gt;library('form_validation'); $post_email = $this-&gt;input-&gt;post('email_id'); $this-&gt;form_validation-&gt;set_rules('email_id', 'Email ID/ Username', 'required|trim|xss_clean|valid_email|callback_check_duplicate_email[' . $post_email . ']'); $this-&gt;form_validation-&gt;set_rules('password', 'Your password', 'required|min_length[5]|max_length[12]|matches[confirm_password'); $this-&gt;form_validation-&gt;set_rules('confirm_password', 'Password Confirmation', 'required'); $this-&gt;form_validation-&gt;set_message('check_duplicate_email', 'This email is already exist. Please write a new email.'); if ($this-&gt;form_validation-&gt;run() == FALSE) { // validation failed then do that $this-&gt;load-&gt;view('member/reg_form'); } else { $data['email_id'] = $post_email; $data['password'] = MD5($this-&gt;input-&gt;post('password')); $insert = $this-&gt;Model_member-&gt;insert_data_to_db($data); if ($insert) { $success = "Wao ! You are successfully added to our community."; $this-&gt;session-&gt;set_flashdata('message_success', $success); $this-&gt;load-&gt;view('member/success_page'); } else { $error = "Hey this email is already exists in our community."; $this-&gt;session-&gt;set_flashdata('message_error', $error); $this-&gt;load-&gt;view('member/reg_form'); } } } // My callback function public function check_duplicate_email($post_email) { return $this-&gt;Model_member-&gt;checkDuplicateEmail($post_email); } </code></pre> <p>Model - </p> <pre><code> //for checking email existance public function checkDuplicateEmail($post_email) { $this-&gt;db-&gt;where('email_id', $email_id); $query = $this-&gt;db-&gt;get('my_registration_table'); $count_row = $query-&gt;num_rows(); if ($count_row &gt; 0) { return TRUE; } else { return FALSE; } } // insert data to DB public function insert_data_to_db($data) { return $this-&gt;db-&gt;insert('my_registration_table', $data); } </code></pre> <p>When I try to submit form with email which is already exists. This function doesn't stop me and doesn't show the validation error message. Would anyone here to see what's the problem? Waiting for your help. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload