Log In · Register

 

Help Topic Rules and Requirements

For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.

This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources

Submission Guidelines

PHP Error Problem
Mikeplyts
post Jun 29 2010, 10:49 AM
Post #1


Mel Blanc was allergic to carrots.
*******

Group: Official Designer
Posts: 6,371
Joined: Aug 2008
Member No: 676,291



So, I'm setting up a form for a user to change their e-mail address. However, there seems to be a conflict with the validation checking and the confirmation checking.

CODE
<?php
$email = $_POST['email'];
$confirm = $_POST['confirm'];

if (count($_POST) > 0) {
    if (!$email) $error = 'Please fill in your e-mail address.';
    else if (!$confirm) $error = 'Please retype your e-mail address.';
    else if ($confirm != $email) $error = 'Please make sure to retype your e-mail address correctly.';
    else if ((!$email == '' && (strstr($email, '@') || strstr($email, '.'))) || (!$confirm == '' && (strstr($confirm, '@') || strstr($confirm, '.')))) $error = 'Please use a valid e-mail address.';
    else {
        update('email');
        $to = $email;
        $subject = 'Your e-mail has been updated.';
        $message = 'Your e-mail address has been successfully changed.';
        $from = 'From: noreply@domain.com';
        mail($to, $subject, $message, $from);
        $error = '';
    }
}

else $error = '';
?>


$error is just echoed later in the page's markup, and update('email') is just a function I defined to update the MySQL database so it wouldn't really have anything to do with my problem. Anyhow, there seems to be some kind of issue between lines 8 and 9 (or 10, if you want to be technical). So, whenever I test it, I try to see if the validation works if the confirmation is correct. For example, I would type "test" in the email field, as well as in the confirm field. That would mean that the confirmation is correct, but for some reason, the validation doesn't do as it should (it should check to see if there's an @ symbol and a period, and if not, produce an error). And since "test" isn't considered a valid e-mail address, it should produce an error, but it doesn't.

I've tried switching the position of the codes, but nothin'. I even tried separating the validation checking code to check for just the email field, and another line for just the confirm field, but no dice. Hell, I even used all if statements. I'm kind of boggled, and some help would be appreciated.

Thanks.
 

Posts in this topic


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: