“提交”按钮未在表单上提交


Submit button not submitting on a form

我已经设置了一个注册表,我的提交按钮不会通过来用注册信息填充我的数据库。代码狙击显示了我的表单的开头和其中包含的一些字段

我把它放在一张桌子上,而不是一张表格上,它似乎起作用了,但当我把它改成表格时,它就停止了作用。我在这里看到了一些其他链接,比如这个HTMLPHP联系表单-提交按钮不工作?还是PHP问题?但我似乎无法让它发挥作用。

<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 --> 

编辑:我的表单在尝试验证后停止向数据库提交信息,很抱歉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
    }

?>

这是我用来填充数据库的全部PHP脚本。//注册点注释下面的所有内容都应该像我在上面添加任何内容之前一样工作。

我没有在文档顶部声明$password和$conPass的变量,这就是阻止提交按钮不工作的原因。

感谢任何人对这篇文章的投入。