Jump to content

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.

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.