Post Check Issue


Im trying to make sure that when a person enters an email address on our form that it is one that we except.

We make busines cards for our clients so we need to check and make sure that the email they provide is with one of our domains…

Here is the code below. What happens is even if the email address is correct it still gives me the error and wont continue.


<?php //Errors error_reporting(E_ALL); ini_set('display_errors', '1'); // Include DB Connection $conn =mysql_connect("xxx","xxx","xxx") or die(mysql_error()); $db = mysql_select_db("xxx") or die(mysql_error()); //Get the Post Name and Email Address from the form $user = $_POST['uname']; $name = $_POST['name']; $address= $_POST['address']; $loc= $_POST['location']; $phone = $_POST['phone']; $fax = $_POST['fax']; $email = $_POST['email']; //Vars $date = date("m/d/y"); $key = $email; $str = $key; $key1 = explode("@", $str); $mykey = $key1[1]; $e = strtolower($mykey); $e1 = ""; $e2 = ""; //Prepare the errors incase they didnt fill in the fields... if ($user == ""){ $err = "Invalid User Id"; }elseif ($name == ""){ $err = "Please enter your Name"; }elseif ($address == ""){ $err = "Please fill in your street Address"; }elseif ($loc == ""){ $err = "Please fill in your Address information"; }elseif ($email == ""){ $err = "Please fill in your Email Address"; }elseif ($e != $e1){ $err = "You must use an Acceptable Email Address"; }elseif ($e != $e2){ $err = "You must use an Acceptable Email Address"; }else{ //Generate a Unique ID for their Business Card $output = ''; $len = 15; $validCharacters = 'abchefghjkmnpqrstuvwxyz1234567890'; while (strlen($output) < $len) { $pointer = rand() % strlen($validCharacters); $nextChar = substr($validCharacters, $pointer, 1); $output .= $nextChar; } $err = "Done Successfuly"; //Lets Input the Information to the Database mysql_query("INSERT INTO ckm_cards (uname, name, email, code, date, street, location, phone, fax) VALUES('".$user."', '".$name."', '".$email."', '".$output."', '".$date."', '".$street."', '".$loc."', '".$phone."', '".$fax."') ") or die(mysql_error()); //Now lets send an Email to Let the SBD Admin know to create the card! $fullname = $name; $sender_email = $email; $subject = 'CKM Business Card Request!'; $message = " Hello SBD Staff Member! Here is a business card request from the user ( $fullname ). Below are the details for the business card. Name: $fullname Email: $email Username: $user Date Sent: $date "; //Define Sender and Reciever $adminemail3 = "[email protected]"; $adminuser = "Staff"; $headers = "From: ".$fullname." <".$email.">rn"; $headers .= 'To: '.$adminuser.' <'.$adminemail.'>'."rn"; $mailit = mail($adminemail3,$subject,$message,$headers); } echo $err; echo "
"; echo $e; ?>


The weird thing is…

If i remove the second check


}elseif ($e != $e2){

		$err = "You must use an Acceptable Email Address";


it then works fine… any ideas why ?

thats because u check for both domains.

the email has to end on “” AND on “

no email will do.

[php]elseif ($e != $e1 && $e != $e2){

$err = “You must use an Acceptable Email Address”;

that way the error is only shown if both fail, and in only one doesn’t match the script will continue.

P.S: i would modyfy it that way:
[php]$e_domains = array();
$e_domains[] = “”;
$e_domains[] = “”;

elseif ( ! in_array($e,$e_domains) ){

$err = “You must use an Acceptable Email Address”;

that way it’s easier to add more domains

Perfect THANKS!!

Sponsor our Newsletter | Privacy Policy | Terms of Service