Jump to content

How do you break out of current code?


Darkmatter5

Recommended Posts

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

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.

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.