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
https://forums.phpfreaks.com/topic/216253-if-statements-keep-running-stop/
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.