1

Good day, will anybody be willing to help me out here. I have this code:

<form id="form_advanced_validation" method="POST" action="">
<div class="row clearfix">
    <div class="col-md-10">
        <div class="form-group form-float">
            <div class="form-line">
                <input type="password" class="form-control" name="oldPass" required>
                <label class="form-label">Old Password</label>
            </div>
        </div>
    </div>
</div>
<div class="row clearfix">
    <div class="col-md-10">
        <div class="form-group form-float">
            <div class="form-line">
                <input type="password" class="form-control" name="newPass" required>
                <label class="form-label">New Password</label>
            </div>
        </div>
    </div>
</div>
<div class="row clearfix">
    <div class="col-md-10">
        <div class="form-group form-float">
            <div class="form-line">
                <input type="password" class="form-control" name="confPass" required>
                <label class="form-label">Confirm Password</label>
            </div>
        </div>
    </div>
</div>
<button class="btn btn-primary waves-effect" type="submit" name="sChanges">SUBMIT</button>

When submit button will be clicked, it will process the change password procedure, this is the code:

if (isset($_POST['sChanges'])) {
$dbC = new imsFunction();

$oldPasswrd = $dbC->txtInput($_POST['oldPass']);
$newPasswrd = $dbC->txtInput($_POST['newPass']);
$confPasswrd = $dbC->txtInput($_POST['confPass']);
$idNumber = $_SESSION['eID'];

if ($newPasswrd <> $confPasswrd) {
    $_SESSION['passConfirm'] = FALSE;
    echo '<script language="javascript">';
    echo 'window.location = "change_Passwd.php";';
    echo '</script>';
} else 

    $dbQry = $dbC->sRowQry('Select * From tbl_endUser Where id_number = ? and id_key = ?',[$idNumber, $oldPasswrd]);

    if ($dbQry->rowCount() > 0) {
        $changePass = $dbC->qryExec('Update tbl_endUser Set id_key=? Where id_number=?',[$newPasswrd, $idNumber]);
        $_SESSION['passChange'] = TRUE;
        echo '<script language="javascript">';
        echo 'window.location = "change_Passwd.php";';
        echo '</script>';
    } else {
        $_SESSION['wrongPass'] = FALSE;
        echo '<script language="javascript">';
        echo 'window.location = "change_Passwd.php";';
        echo '</script>';
    }

    $dbC->disConnect(); }

What I want to do is when "$_SESSION['passChange']" has been set, I would like to call this javascript function:

function showSuccessMessage() {
swal("Good job!", "Password has been changed!", "success");}

I tried:

if (isset($_SESSION['passConfirm'])) { echo '<script type="javascript"> showSuccessMessage(); </script>'; }

but nothing happened.. Please guys, help me.

3
  • i think you may have wrong variable name here. $_SESSION['passChange'] or $_SESSION['passConfirm'] ?? Commented Mar 15, 2017 at 5:44
  • you can give this message without script. Commented Mar 15, 2017 at 5:44
  • error has been corrected, however, it seems that the function showSuccessMessage() was not called. Commented Mar 15, 2017 at 6:06

1 Answer 1

1

Don't forget to use session_start(); at beginning of each page.

Before calling the function, just use echo $_SESSION['passConfirm']; to ensure the session is set.

Now correct your code based on above 2 things and check

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. session_start(); is present in each page, then $_SESSION['passChange']/['passConfirm'] has been set. actually, password has been change after that. However, the function showSuccessMessage() { swal("Good job!", "Password has been changed!", "success");} was not called..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.