1

I am studying codeigniter by developing a website locally. My doubt is, I added some fields in table as unique.

When I try to add duplicate values, It shows internal server error

I overcome this by add function for check if it is a duplicate entry. But I need to add this function on each table insertion.

My question is, Is there any way to write a function at My_model.php for check a table and a unique field value and call it in the My_controller.php by passing the table name and unique field value

1 Answer 1

3

You can use Codeigniter's default form validation to check if the new value being added to the unique field already exists in DB or not.

Refer this:

is_unique | Returns FALSE | if the form element is not unique to the table and field name in the parameter. is_unique[table.field]

this->form_validation->set_rules('email', 'Email', 'required|is_unique[users.email]');

Sign up to request clarification or add additional context in comments.

1 Comment

Wow.. and it works..thank you for the answer. Will accept the answer once the waiting period over... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.