Jump to content

if statements keep running - STOP!!


unistake

Recommended Posts

I have made a script that allows a user to change their email address. It works BUT if the email address they have chosen is already registered the script does not cut off - it continues to the next if statement and changes the email address anyway.

 

I am trying to put a stop to it using exit() and exit; but it does not work.

 

Any tips?

 

<?php
//////////////////// checking new email is not already registered /////////////////
if ($_POST['newemail'] && $_POST['newemail1'] !="") {

if ($_POST['newemail'] == $_POST['newemail1']) {
	$sql2 = "SELECT email FROM Members WHERE email='$_POST[newemail]'";
	$result2 = mysqli_query($cxn,$sql)
		or die ("Couldn't execute query 2");

	$num2 = mysqli_num_rows($result2);

	if ($num2 > 0) { $updateerror = "The email address you have chosen is already registered.";
					 include("my-account.php")
					 exit();  // TRYING TO STOP THE SCRIPT HERE (IF $num2 > 0)
					 exit;
	}
	else { echo "You can have this new email address";}
}
else { echo "Your email addresses do not match. Please try again.";	}
}
else {}

// THIS SCRIPT CONTINUES TO CHANGE THE EMAIL ADDRESS DESPITE IT ALREADY BEING REGISTERED.
if ($_POST['newemail'] == "") { $newemail = $_POST['currentemail']; }
else { $newemail = $_POST['newemail']; }
$newemail1 = $_POST['newemail1'];
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.