Darkmatter5 Posted November 12, 2008 Share Posted November 12, 2008 I have some code with a few if statements and if my password and password confirmation text boxes don't match I want to break out of the if statement and tell the user the passwords didn't match. Here's the code: if (isset($_POST['save'])) { $member_id=$_SESSION['member_id']; if($_POST['firstname']!='') { $values[]="mem_firstname='$_POST[firstname]'";} if($_POST['lastname']!='') { $values[]="mem_lastname='$_POST[lastname]'";} if($_POST['email']!='') { $values[]="mem_email='mysql_real_escape_string($_POST[email])'";} if($_POST['password']!='' && $_POST['con_password']!='') { if($_POST['password']==$_POST['con_password']) { $values[]="'md5($_POST[password])'"; } else { echo "Passwords did not match!"; } } foreach($values as $value) { $updatedata="UPDATE $pagedb SET $value WHERE member_id=$member_id"; mysql_query($updatedata) or die($updatedata . '<br >'.mysql_error()); } echo "Changes have been saved! Click <a href='res_accmaint.php'>here</a> to reload your profile."; } Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/132476-how-do-you-break-out-of-current-code/ Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 break; may work but I do not think so. I think the only way is to re-do your if statements. if (isset($_POST['save'])) { if(($_POST['password']!='' && $_POST['con_password']!='') && $_POST['password']==$_POST['con_password']) { $values[]="'md5($_POST[password])'"; $member_id=$_SESSION['member_id']; if($_POST['firstname']!='') { $values[]="mem_firstname='$_POST[firstname]'";} if($_POST['lastname']!='') { $values[]="mem_lastname='$_POST[lastname]'";} if($_POST['email']!='') { $values[]="mem_email='mysql_real_escape_string($_POST[email])'";} foreach($values as $value) { $updatedata="UPDATE $pagedb SET $value WHERE member_id=$member_id"; mysql_query($updatedata) or die($updatedata . '<br >'.mysql_error()); } echo "Changes have been saved! Click <a href='res_accmaint.php'>here</a> to reload your profile."; }else { echo "Bad Password!"; } } I believe that will get you your desired effect. Link to comment https://forums.phpfreaks.com/topic/132476-how-do-you-break-out-of-current-code/#findComment-688767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.