Title: Restriction for not allowing same email and password in the database for my signup form
Tags: codeigniter
Question: i want to make a restriction in my signup form which the user cant signup with the already exists email and password..
in my controller:
i already make a rules or callback
array(
'field'   =&gt; 'txt_email',
'label'   =&gt; 'Email',
'rules'   =&gt; 'required|valid_email|callback_check_if_valid_email|trim',
),
check_if_valid:
public function check_if_valid_email()
$where  = array('email'      =&gt;$this-&gt;input-&gt;post('txt_email'),'password'   =&gt;$this-&gt;input-&gt;post('txt_password'));
$this-&gt;load-&gt;model('database_model');
if ($user = $this-&gt;database_model-&gt;validate_user('user', $where))
{
foreach ($user as $row) {
$checkemail = $row-&gt;email;
$checkpassword = $row-&gt;password;
}
if ($checkemail == $this-&gt;input-&gt;post('txt_email')){
$this-&gt;form_validation-&gt;set_message('check_if_valid_email', 'Email already existed!');
return false;
}
else
{
if ($checkpassword = $this-&gt;input-&gt;post('txt_password'))
{
$this-&gt;form_validation-&gt;set_message('check_if_valid_email', 'Email already exists!');
return false;
}
else
{
return true;
}
}
}
in my model:
public function validate_user($table, $where)
$this-&gt;db-&gt;where($where);
$query = $this-&gt;db-&gt;get($table);
if ($query-&gt;num_rows() &gt; 0)
return $query-&gt;result();
else
return false;

Here is the accepted answer: CodeIgniter's Form Validation library comes with the rule you're looking for, called: is_unique
http://www.codeigniter.com/userguide3/libraries/form_validation.html#rule-reference
Your validation rules will look like this;
required|valid_email|is_unique[users.email]|trim
All you have to set it the table and column you want to be unique (users.email).
Hope this helps.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:08/21/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<codeigniter>', 'Title': 'Restriction for not allowing same email and password in the database for my signup form', 'ViewCount': 40, 'id': 32140702, 'user_AboutMe': None, 'user_AccountId': 6820302.0, 'user_DisplayName': 'Bernard Arthur Rico Tubog', 'user_Reputation': 57.0, 'user_Views': 22.0, 'user_id': 5247667.0}}