I am working on a site in codeigniter.I am not so expert using framework.Here I have to check if email already exists in database.I have coded the required functionality but
You have an error in the mysql query:-
SELECT * WHERE ` = 'muraddnw@gmail.com' LIMIT 1
Your code has not specified which table to query from. So use following:-
$this->db->select('id');
$this->db->from('tablename');
$this->db->where('email', $email);
Hope this helps.
$this->form_validation->set_rules('username', 'userName', 'required|callback_exists_username');
#uniqueness of username
function exists_username($str)
{
$record_id = $this->input->post('record_id');
$condition = array('user_id !='=>$record_id,'username'=>$str);
$value =GetAllRecord('user_master',$condition,$is_single=true);
if (count($value) == 0)
{
return TRUE;
}
else
{
$this->form_validation->set_message('exists_username', 'username already exists!');
return FALSE;
}
}
Use is_unique[table.field]
add table name and field.
$this->form_validation->set_rules(
'email', 'Email', 'trim|required|valid_email|is_unique[table.field]|callback_isEmailExist'
);
you can check if a field is unique or not by using form_validator function is_unique[table_name.field_name]
no need to a make a special function, this is enough
$this->form_validation->set_rules(
'email', 'Email', 'trim|required|valid_email|is_unique'
);
Your problem is in the set_rules line. Here you use both is_unique
and a callback
function. You have to use anyone of that. If you use a call_back function to check duplicate data; doesn't need to use is_unique. For this wrong you get that error
Just remove the is_unique
from there.
$this->form_validation->set_rules('email','Email','trim|required|valid_email|callback_isEmailExist'); // removed is_unique
Try this out and let me know.