如何修复"语法错误,意外的'}' &#34 ;?

时间:2017-11-11 21:07:09

标签: php syntax

以下是我的代码,我无法找到此错误的修复程序:语法错误,意外情况'}'。

代码:

<?php       if (isset($_POST['oldpass']) and isset($_POST['newpass']) and isset($_POST['confnewpass'])) {
            $old_pass = $_POST['oldpass'];
            $new_pass = $_POST['newpass'];
            $compare_pass = $_POST['confnewpass'];
            $hash_password = password_hash($new_pass, PASSWORD_DEFAULT);
            // Checking the values are existing in the database or not
            $servername = "localhost";
            $dbusername = "";
            $dbpassword = "";
            $dbname = "";
            $conn2 = new mysqli($servername, $dbusername, $dbpassword, $dbname);
            $conn2->set_charset("utf8");
            if($conn2->connect_error){
                die("Connection failed: " . $conn2->connect_error);
            }
            $stmt2 = $conn2->prepare("SELECT password FROM users WHERE username = ?");
            $stmt2->bind_param('s', $username);
            $stmt2->execute();
            $result2 = $stmt2->get_result();
            $row2 = $result2->fetch_array(MYSQLI_ASSOC);
            if ($username && password_verify($old_pass, $row2['password'])){
                if ($new_pass === $compare_pass){
                    $stmt3 = $conn2->prepare("UPDATE users SET password = ? WHERE username = ?");
                    $stmt3->bind_param('ss', $hash_password, $username);
                    $stmt3->execute();
                    $result3 = $stmt3->get_result();
                    $row3 = $result3->fetch_array(MYSQLI_ASSOC);
                    if ($row3){
                        $gmsg = "Password has been successfully updated.";
                    }else{
                        $bmsg = "Password was not updated.";
                    }
                }else{
                    $bmsg = "Passwords do not match.";
                }
            }else{
                $bmsg = "Old Password is incorrect.";
            }
        }else{
            $bmsg = "One of the fields were not set."
        }?>

错误发生在代码的最后一行。

提前致谢!

1 个答案:

答案 0 :(得分:1)

在最后一行你忘了;

else{
            $bmsg = "One of the fields were not set.";
        }