vendredi 30 octobre 2020

PHP MySQL If nothing changed, process the rest

I have an update info form. I want it to check if the new email is already taken. BUT if the email stays the same, then just update the rest of it. I have tried several IF statements, but nothing seems to work, it always says, "email already taken". So if someone could point me in a good direction, i would be greatly appreciative.

Here is a sample of the code:

$user_name = validate_text($_POST['user_name']);
        $user_email = validate_email($_POST['user_email']);
        $user_country = validate_text($_POST['user_country']);
        $user_state = validate_text($_POST['user_state']);

        $edit_id = $_SESSION['user_data']['id'];

        $db->query('SELECT * FROM users WHERE user_email = :user_email');
        $db->bind('user_email', $user_email, PDO::PARAM_STR);
        $check_user_email = $db->fetchSingle();

        if ($check_user_email > 0) {
            if ($check_user_email != $user_email) {
                setAlert('<div class="alert alert-danger text-center" role="alert">That Email is already in use</div>');
            } else {
                $db->query('UPDATE users SET user_name=:user_name, user_email=:user_email, user_country=:user_country, user_state=:user_state WHERE user_id=:user_id');

Aucun commentaire:

Enregistrer un commentaire