Check if data already exists in codeigniter bank

Asked

Viewed 1,631 times

2

I’m starting with codeigniter using active record to make the conversation with the bank, and wanted to know how to know if an email already exists in db, would have to list all email and create a foreache doing the checking? Is there a simpler way?

  • No, make a query at the bank specifying(where) the value you want to find.

2 answers

2

You can do with the library form_validation. You pass the name of the field that should be unique and the table name.

The is_unique will validate this.

is_unique[tbUsuario.campoEmail]

Stay like this

$this->form_validation->set_rules('inputEmail', 'Email', 'required|valid_email|is_unique[tbUsuario.campoEmail]');

The inputEmail must be replaced by the name of its HTML input, then the table name and the field name in the database. Adjust to your template.

Then execute the validation:

if(!$this->form_validation->run())
   ... fluxo de erro aqui  

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.