html - I'm trying to enable password strength validation in PHP but I'm not sure what I'm doing wrong

one text

result of code

Here is my code:

<?php
require 'db.php';
if (isset($_POST['submit'])) {
    $password = $_POST['password'];

    // Validate password strength
    $uppercase    = preg_match('@[A-Z]@', $password);
    $lowercase    = preg_match('@[a-z]@', $password);
    $number       = preg_match('@[0-9]@', $password);
    $specialchars = preg_match('@[^\w]@', $password);

    if (!$uppercase || !$lowercase || !$number || !$specialchars || strlen($password) < 8) {
        echo 'Password is not Strong';
    } else {
        echo 'Password is Strong';
    }
}

// When form submitted, insert values into the database.
if (isset($_REQUEST['accnumber'])) {
    // removes backslashes
    $accnumber = stripslashes($_REQUEST['accnumber']);
    //escapes special characters in a string
    $accnumber = mysqli_real_escape_string($con, $accnumber);
    $password = stripslashes($_REQUEST['password']);
    $password = mysqli_real_escape_string($con, $password);
    $query = "INSERT into `users` (accnumber, password)
                VALUES ('$accnumber', '" . md5($password) . "')";
    $result = mysqli_query($con, $query, $password);
    if ($result) {
        echo "<div class='form'>
            <h3>You have successfully registered .</h3><br/>
            <p class='link'>Click here to <a href='login.php'>Login</a></p>
            </div>";
    } else {
        echo "<div class='form'>
            <h3>Required fields are missing.</h3><br/>
            <p class='link'>Click here to <a href='registration.php'>register</a> again.</p>
            </div>";
    }
} else {
?>

Essentially I'm trying to merge the two if else statements. I want to check the password for strength first. Then if it is okay, it puts it inside the database and echo's that you have successfully logged in. If you don't meet the security requirements then it echos that the password is not strong and to try again. I was able to make the first if statement work but it doesn't carry down to the second.

Source