Case in PHP [closed]

-3

I'm having a somewhat unusual (or not common) problem. I have an email address field. The user adds an email, the system verifies that the email already exists in the database, if not it registers, if it does not, it does not register.

It turns out that if the user differentiates a letter from the email to uppercase the system interprets the email differently. For example, there is an email in the DB: "[email protected]", if a user tries to register the email "[email protected]" the system allows.

What can I do to disable this case? Or is it not necessary? the system has to do this same scan.

    
asked by anonymous 18.07.2018 / 17:12

2 answers

1

The easiest way would already be in INSERT to treat all the strings that are used for comparisons (in PHP, because in the database, depending on which uses is not case sensitive).

Complementing what Lucas said, the easiest forms would be:

strtolower () : convert string to lowercase

Example:

$str = "[email protected]";
$str = strtolower($str);
echo $str; // Resultado: [email protected]

strtoupper () : convert a string to uppercase : p>

Example:

$str = "[email protected]";
$str = strtoupper($str);
echo $str; // Resultado: [email protected]
    
18.07.2018 / 17:33
0

You can use the strtolower () function to convert the entire string to lowercase and query the database with a return of that function.

$email = strtolower($email);

    
18.07.2018 / 17:26