Search
 
SCRIPT & CODE EXAMPLE
 

PHP

How to Validate an Email Duplicate Entry in Codeigniter

// THIS HELPER METHOD CHECKS IF THE EMAIL IS VALID OR NOT. IT BASICALLY CHECKES THE DUPLICATION
function email_duplication($email = "", $user_id = "")
	{
		$CI	= &get_instance();
		$CI->load->database();

		if (filter_var($email, FILTER_VALIDATE_EMAIL)) { //FILTER MAIL FIRST
			
			$query = $CI->db->get_where('users', ['email' => $email]);
			if (!empty($user_id)) { //IF USER-ID EXIST
				$query_result = $query->row_array();
				if ($query->num_rows() == 0 || $query_result['id'] == $user_id) { //IF NOT FIND ANY DUBLICATE
					return true;
				} else { //IF FIND
					$CI->session->set_flashdata('notice_message', get_phrase('Email_already_exists'));
					redirect($_SERVER['HTTP_REFERER'], 'refresh');
				}
			} else { //WHEN USER ID NOT EXIST
				if ($query->num_rows() > 0) { //FIND DUBLICATE
					$CI->session->set_flashdata('notice_message', get_phrase('Email_already_exists'));
					redirect($_SERVER['HTTP_REFERER'], 'refresh');
				} else { //NOT FIND
					return true;
				}
			}

		} else { //INVALID EMAIL
			$CI->session->set_flashdata('error_message', get_phrase('Invalid_email'));
			redirect($_SERVER['HTTP_REFERER'], 'refresh');
		}
		

	}
Comment

PREVIOUS NEXT
Code Example
Php :: building an ecommerce website with laravel 
Php :: fetch data from database withour restarting console php 
Php :: mamp change php version 
Php :: php get current datetime in us chicago 
Php :: Laravel - Controller get select value from Views 
Php :: : in php 
Php :: JsonResource::withoutWrapping 
Php :: php objects 
Php :: laravel sintax 
Php :: Funktion umgekehrt ausgeben, strrev 
Php :: symfony clear session 
Php :: Explicit Octal numeral notation - PHP 8.1 
Php :: laravel yajra datatable Add Column with View 
Php :: Yii2: Setting default values for all attributes of a model 
Php :: 0.1 eth to php 
Php :: DB::raw update query in laravel 
Php :: length shorter 
Php :: Stopping On First Validation Failure 
Php :: wc php order view order link 
Php :: gan_sql 
Php :: laravel notion add enviroment 
Php :: remove a specific element from array inside a loop php 
Php :: get first row of array php 
Php :: Database connection use for validation in laravel 8 
Php :: change varchar limit in migration file. 
Php :: database interaction in codeigniter 
Php :: build_Assoc 
Php :: Drupal 9 select node data with query conditions using entity type manager 
Php :: remove public from url laravel 
Php :: ph address format 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =