unistake Posted October 19, 2010 Share Posted October 19, 2010 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 More sharing options...
trq Posted October 19, 2010 Share Posted October 19, 2010 exit will definitely stop your script in its tracks, are you sure its even getting to the exit call? Link to comment https://forums.phpfreaks.com/topic/216253-if-statements-keep-running-stop/#findComment-1123827 Share on other sites More sharing options...
unistake Posted October 19, 2010 Author Share Posted October 19, 2010 yes it is as the whole script below is updating information it should not! I will have another look at it. Link to comment https://forums.phpfreaks.com/topic/216253-if-statements-keep-running-stop/#findComment-1123828 Share on other sites More sharing options...
unistake Posted October 19, 2010 Author Share Posted October 19, 2010 yes it works, error on my part. Thanks Link to comment https://forums.phpfreaks.com/topic/216253-if-statements-keep-running-stop/#findComment-1123831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.