Jump to content

[SOLVED] Is this right?


tqla

Recommended Posts

Hi. I am trying to compare two email fields and declare them "$bad_email_format[] = $field;" if they do not match. This looks right to me but it doesn't work. Where am I going wrong?

 

    elseif ($field == "email" )
    {
        if ('email' != 'confirmEmail' )
        {
             $bad_email_format[] = $field;
        }
    }

Link to comment
https://forums.phpfreaks.com/topic/58495-solved-is-this-right/
Share on other sites

What is this line?

if ('email' != 'confirmEmail' )

 

Shouldn't "email" and "confirmEmail" be post data variables from what the user filled out? Maybe something like this...

 

if ($_POST['email'] != $_POST['confirmEmail'])

 

Could you post more code so we can see what all the form values/information should be?

Link to comment
https://forums.phpfreaks.com/topic/58495-solved-is-this-right/#findComment-290106
Share on other sites

Hi pocobueno1388. Come to think of it, I am not using $_POST['data'] at all and everything works except the 'email/confirmEmail' comparison. It shows the error message "Emails do not match" no matter if they do or don't.

 

Here's the entire script:

 

<?php
session_start();
require_once('db/db.php');
?>
<?php
/* set up array containing all the fields */
  $labels = array ( "clubCard" => "Club Card Number",
  					"firstName" => "First Name",
                    "lastName" => "Last Name",
                    "address" => "Address",
				"additionalAddress" => "Additional Address",
				"city" => "City",
				"state" => "State",
				"zip" => "Zip Code",
				"email" => "Email Address",
				"confirmEmail" => "Confirm Email Address",
				"okToContact" => "OK To Contact");
  foreach ($_POST as $field => $value)
  {
    /* check each field for blank fields */
    if ( $value == "" )
    {
       if ($field != "clubCard" and $field != "additionalAddress" and $field != "okToContact" )
       {
          $blank_array[] = $field;
       }
    }
    /* check text for invalid formats. */
    elseif ($field == "address" or $field == "clubCard" or $field == "additionalAddress" )
    {
        if (!ereg("^[A-Za-z0-9'.# -]{1,50}$",$_POST[$field]) )
        {
             $bad_format[] = $field;
        }
    }
/* check text for invalid formats. */
    elseif ($field == "firstName" or $field == "lastName" 
or $field == "city" or $field == "state" )
    {
        if (!ereg("^[A-Za-z'. -]{1,50}$",$_POST[$field]) )
        {
             $bad_format[] = $field;
        }
    }
    /* check zip for invalid format. */
    elseif ($field == "zip")
    {
      if(!ereg("^[0-9]{5,5}(\-[0-9]{4,4})?$",$value))
      {
           $bad_format[] = $field;
      }
   }
 /* check email for invalid formats. */
    elseif ($field == "email" )
    {
        if ('email' != 'confirmEmail' )
        {
             $bad_email_format[] = $field;
        }
    }
  }
  /* if any fields are not okay, display error message and form */
  if(@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0 or @sizeof($bad_email_format) > 0)
  {
    if(@sizeof($blank_array) > 0)
    {
        /* display message for missing information */
        $error_text .= "<b><font face=\"verdana\" color=\"#ff0000\">You didn't fill in one or more required 
	         fields. You must enter:</b><br> </font>";
	$errors = 'yes';
        /* display list of missing information */
        foreach($blank_array as $value)
        {
           $error_text .= "<font face=\"verdana\" color=\"#ff0000\">      {$labels[$value]}<br></font>";
	   $errors = 'yes';
        }
    }
    if(@sizeof($bad_format) > 0)
    {
        /* display message for bad information */
        $error_text .= "<BR><font face=\"verdana\" color=\"#ff0000\"><b>One or more fields have information that appears to be 
                 incorrect. Correct the format for:</b><br></font>";
    $errors = 'yes';
        /* display list of bad information */
        foreach($bad_format as $value)
        {
           $error_text .= "<font face=\"verdana\" color=\"#ff0000\">      {$labels[$value]}<br></font>";
	   $errors = 'yes';
        }
    }
if(@sizeof($bad_email_format) > 0)
    {
        /* display message for bad information */
        $error_text .= "<BR><b><font face=\"verdana\" color=\"#ff0000\">Emails do not match</b><br></font>";
	$errors = 'yes';
        /* display list of bad information */
        foreach($bad_email_format as $value)
        {
           $error_text .= "<font face=\"verdana\" color=\"#ff0000\">      {$labels[$value]}<br></font>";
	   $errors = 'yes';
        }
    }
    /* redisplay form */
    include("page1.php");
    exit();
  }
  /* if data is good */
$_SESSION['clubCard'] = $clubCard;
$_SESSION['firstName'] = $firstName;
$_SESSION['lastName'] = $lastName;
$_SESSION['address'] = $address;
$_SESSION['additionalAddress'] = $additionalAddress;
$_SESSION['city'] = $city;
$_SESSION['state'] = $state;
$_SESSION['zip'] = $zip;
$_SESSION['email'] = $email;
$_SESSION['confirmEmail'] = $confirmEmail;
$_SESSION['okToContact'] = $okToContact;

header("Location: nextpage.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/58495-solved-is-this-right/#findComment-290120
Share on other sites

/* check email for invalid formats. */

    elseif ($field == "email" )

    {

        if ('email' != 'confirmEmail' )

        {

            $bad_email_format[] = $field;

        }

    }

  }

 

thats what hes saying sure always ! if ('email' != 'confirmEmail' )

Link to comment
https://forums.phpfreaks.com/topic/58495-solved-is-this-right/#findComment-290124
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.