check value already exists in codeigniter

Callback function of codeigniter which checks whether the value already exists in particular column of table or not.

This function work on add and edit both cases,it return false if value exists and return true if value not exists.

following is the function that you need to put in your controller file:

Note: change the table name in function and in edit case you can change the primary key!= with your table’s key name.

Now time to using this callback function for adding and editing forms.We need to pass the callback function in validation rules.

For the time of adding you can pass the rule in your add action like as:

and in your edit action you can use the rule as following:

Thanks for reading full article , Now use it in your project and if you face any trouble then comment here.