emailExists (function)

Last updated: Mon, Apr 17, 2023 8:21 am
Return to Knowledgebase

Purpose

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $email string Yes queries the database and check whether a user with the given email exists in the users table

Returns

Data Type Description of Returned Data
bool The function returns a boolean value, true if the email address exists in the users table and false if it does not exist.

Further Documentation:

The function first creates an instance of the UserSpice database class (DB::getInstance()) and then executes a SQL query to select the email column from the users table where the email matches the given $email. The function then checks if any results were returned, and if so, it returns true to indicate that the email exists in the table. If no results were returned, it returns false to indicate that the email does not exist in the table.

Here is an example of how to use the emailExists function:

Suppose you have a website with user registration, and you want to check whether a given email address is already registered in the users table. You can use the emailExists function like this:

if (emailExists('test@example.com')) {
echo 'This email is already registered';
} else {
echo 'This email is available';
}


This will check whether the email address 'test@example.com' exists in the users table, and output a message indicating whether the email is already registered or available for registration.

You can also use a variable to specify the email address, like this:

$user_email = 'test2@example.com';
if (emailExists($user_email)) {
echo 'This email is already registered';
} else {
echo 'This email is available';
}


This will check whether the email address stored in the $user_email variable exists in the users table, and output a message indicating whether the email is already registered or available for registration.