提交未在表单上提交的按钮

I have set up a registration form and my submit button won't pass through to populate my database with the registration information. The code snipet shows the start of my form and some fields that are included in it.

I had this set up in a table, rather than a form and it seemed to work but when I changed it to a form it stoped working. I've looked at a few other links on here such as this one HTML PHP Contact Form - Submit Button Not Working? Or PHP Issue? But I can't seem to get it working.

<div class = "contact">
        <form class="form-horizontal" role="form" method="post" action=" <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">Username:</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="username" name="username" value="<?php echo $username ?>">
                <span class="error"><?php echo getErrorMessage('username', $error); ?></span>
            </div> 
        </div>
            
        <div class="form-group">
            <label for="password" class="col-sm-2 control-label">Password:</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="password" name="password" value="<?php echo $password ?>">
            </div>
        </div>
        
        <div class="form-group">  
            <label for="conPass" class="col-sm-2 control-label">Confirm Password:</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="conPassword" name="conPassword" value="<?php echo $conPass ?>">
            </div>

        <div class="col-sm-10">
            <input id="button" name="reg" type="submit" value="Register" class="btn btn-primary">
        </div>    
        </div> <!-- registration button --> 
        
        </form>
    </div> <!-- registration end --> 

EDIT: my form stopped submitting information to the database after I tried to validate it, sorry for the incomplete posts very new to Stack Overflow

<?php
    include "config.php"; 

    //error_reporting(0); 

/*  $username = $_POST['username']; 
    $password = md5($_POST['password']."ALS52KA09W");
    $conPass = md5($_POST['conPass']."ALS52KA09W");
    $telephone = $_POST['telephone'];
    $address1 = $_POST['address1'];
    $town = $_POST['town'];
    $postcode = $_POST['postcode'];
    $forename = $_POST['forename'];
    $surname = $_POST['surname'];
    $email = $_POST['email']; */

    //declaring variables as empty strings
    $username = $forename = $surname = $email = $telephone = $address1 = $town = $postcode =""; 
    $error = array();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (empty($_POST["username"])) 
        {
        $error['username'] = "* Username is required";
        } else { 
        $username = test_input($_POST["username"]);
            if (!preg_match("/^[a-zA-Z ]*$/",$username)) 
            {
            $error['username'] = "* Only letters and white space allowed in name";
            }// end if
                  } //end username

        if (empty($_POST["forename"])) 
        {
        $error['forename'] = "* Forename is required";
        } else { 
        $forename = test_input($_POST["forename"]);
            if (!preg_match("/^[a-zA-Z ]*$/",$forename)) 
            {
            $error['forename'] = "* Only letters and white space allowed in forename";
            }// end if
                  } //end forename

        if (empty($_POST["surname"])) 
        {
        $error['surname'] = "* Surname is required";
        } else { 
        $surname = test_input($_POST["surname"]);
            if (!preg_match("/^[a-zA-Z ]*$/",$surname)) 
            {
            $error['surname'] = "* Only letters and white space allowed in forename";
            }// end if
                  } //end surname

        if (empty($_POST["email"])) 
        {
            $error['email'] = "* Email is required";
        } else {
            $email = test_input($_POST["email"]);
            // check if e-mail address syntax is valid
            if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) 
            {
                $error['email'] = "* Invalid email format";
            }
               } //end email validation

        if (empty($_POST["telephone"])) 
        {
            $error['telephone'] = "* Telephone is required";
        } else {
                $telephone = test_input($_POST["telephone"]);
                // check telephone only contains numbers and is length 11
            if((preg_match("/[^0-9]/", '', $str)) && strlen($str) == 11)
            {
                $error['telephone'] = "* Please enter a valid telephone number";
            }
                   } //end telephone validation

        /* if (empty($_POST["address1"])) 
        {
            $error['address1'] = "* Address is required";
        } else {
            $address1 = test_input($_POST["address1"]);
            // check if address has letters and numbers
            if (!preg_match("/([A-Za-z0-9]+)/", $address1)) 
            {
                $error['address1'] = "* The address field must contain numbers and letters ";
            }
               } //end address validation */

        if (empty($_POST["town"])) 
        {
            $error['town'] = "* Town is required";
        } else {
                $town = test_input($_POST["town"]);
                // check town only contains letters and whitespace
            if (!preg_match("/^[a-zA-Z ]*$/",$town)) 
            {
                $error['town']= "* Only letters and white space allowed";
            }
                } //end town validation

        if (empty($_POST["postcode"])) 
        {
            $error['postcode'] = "Postcode is required";
        } else {
                $postcode = test_input($_POST["postcode"]);
                // check postcode validation and syntax
            if (preg_match ("^[A-Z]?[A-Z][0-9][A-Z0-9]?\s[0-9][A-Z]{2}$^", $postcode))
            {
                $error['postcode'] = "Wrong postcode syntax.  Valid syntax = XX00 0XX";
            }
                } //end postcode validation

    if (!count($error)) {
         $noError = true;
    }
} //end server request method 

    $successMessage = isset($noError) ? 'Thank you for registering with us.' : '';

    function test_input($data) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }

    function getErrorMessage($type, $error)
    {
        return isset($error[$type]) ? $error[$type] : '';
    }



    //Registration point
    if(isset($username,$password,$conPass,$forename,$surname,$email,$telephone,$address1,$town,$postcode))
    {
        if($password == $conPass)
        {
            $q = $db->prepare("SELECT * FROM user WHERE username = ?");
            $query = $q-> execute(array($username));
            $count = $q->rowCount();
            if($count == 0)
            {
                $query = $db->prepare("INSERT INTO user SET username = ?, password = ?, forename = ?, surname = ?, email = ?, telephone = ?, address1 = ?,
                                                            town = ?, postcode = ?");
                $query = $query->execute(array($username,$password,$forename,$surname,$email,$telephone,$address1,$town,$postcode));
                    if($query){
                        echo $successMessage;
                        header("Location:home2_template.html");
                        return; 
                    }
            }else{
                echo "This user already exists";
            }

        }else{
            echo "Your passwords do not match";
        } //Error checking
    }


?>

This is my total PHP script to populate the database. Everything below the //Registration point comment should work as it was working before I added anything above it.

</div>

I didn't declare the variables of $password and $conPass at the top of my document and that's what was stopping the submit button not to work.

Thanks for anyone's input on this post.