Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Boostrap表单不会将数据提交到数据库_Php_Html_Forms_Bootstrap 4 - Fatal编程技术网

Php Boostrap表单不会将数据提交到数据库

Php Boostrap表单不会将数据提交到数据库,php,html,forms,bootstrap-4,Php,Html,Forms,Bootstrap 4,我有一个模式内的引导表单,但我无法获取数据提交到我的数据库 我的模态表单html <div class="modal-body"> <form method="post" action="insertRecord.php"> <div class="form-group"> <label for="firstName">First Name</label> <

我有一个模式内的引导表单,但我无法获取数据提交到我的数据库

我的模态表单html

<div class="modal-body">

      <form method="post"  action="insertRecord.php">
        <div class="form-group">
          <label for="firstName">First Name</label>
          <input type="text" name="txtFirstName"  class="form-control" id="inputFirstName" placeholder="First Name">
        </div>
        <div class="form-group">
          <label for="lastName">Last Name</label>
          <input type="text" name="txtLastName" class="form-control" id="inputLastName" placeholder="First Name">
        </div>
        <div class="form-group">
          <label for="emailAddress">Email address</label>
          <input type="email" name="txtEmail" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
          <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
        </div>
        <div class="form-group">
          <label for="password">Password</label>
          <input type="password" name="txtPassword" class="form-control" id="exampleInputPassword1" placeholder="Password">
        </div>
        <div class="form-group">
          <label for="Dob">Date of birth:</label>
          <input type="date" name="DoB" class="form-control" id="inputDOB" placeholder="First Name">
        </div>
        <div class="form-group">
          <label for="Address1">Address1</label>
          <input type="text" name="txtAddress1" class="form-control" id="inputAddress1" placeholder="First Name">
        </div>
        <div class="form-group">
          <label for="Address2">Address2</label>
          <input type="text" name="txtAddress2" class="form-control" id="inputAddress2" placeholder="First Name">
        </div>
        <div class="form-group">
          <label for="postcode">Postcode</label>
          <input type="text" name="txtPostcode" class="form-control" id="inputPostcode" placeholder="First Name">
        </div>
        <input type="submit" value="Submit" name="taxSubmit"  />
      </form>

    </div>
我的代码插入表单信息php

<?php

include 'connection.php';

$firstName=$_POST['txtFirstName'];
$lastName=$_POST['txtLastName'];
$email=$_POST['txtEmail'];
$password=$_POST['txtPassword'];
$dob=$_POST['DoB'];
$address1=$_POST['txtAddress1'];
$address2=$_POST['txtAddress2'];
$postcode=$_POST['txtPostcode'];


$query="INSERT INTO Userinfo (FirstName, LastName, 
Email,Password,Dob,Address1,Address2,Postcode) VALUES ('$firstName', 
'$lastName', 
'$email','$password','$dob','$address1','$address2','$postcode')";




mysqli_query($connection, $query);
?>
我有另一个连接到数据库的脚本,我将感谢任何我能得到的帮助,因为我已经被困在这个问题上好几个小时了,我无法解决这个问题


非常感谢

试试这个例子,我跑步了,效果很好:

<?php
require 'connection.php';

$firstName = $lastName = $email = $email = $password = $dob = $address1 = $address2 = $postcode = $query = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $firstName = $_POST['txtFirstName'];
    $lastName = $_POST['txtLastName'];
    $email = $_POST['txtEmail'];
    $password = $_POST['txtPassword'];
    $dob = $_POST['DoB'];
    $address1 = $_POST['txtAddress1'];
    $address2 = $_POST['txtAddress2'];
    $postcode = $_POST['txtPostcode'];


    $query = "INSERT INTO Userinfo (FirstName, LastName, 
    Email, Password, Dob, Address1, Address2, Postcode) VALUES ('$firstName', 
    '$lastName', '$email','$password','$dob','$address1','$address2','$postcode')";
}
echo $query;
if (mysqli_query($connection, $query)) {
echo "New record created successfully";
} else {
echo "Error: " . $query. "<br>" . mysqli_error($connection);
}

mysqli_close($connection);
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Insert Example</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>

        <div class="container">
            <h2>Modal</h2>
            <!-- Trigger the modal with a button -->
            <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

            <!-- Modal -->
            <div class="modal fade" id="myModal" role="dialog">
                <div class="modal-dialog">

                    <!-- Modal content-->
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">Modal Header</h4>
                        </div>
                        <div class="modal-body">

                            <form method="post"  action="">
                                <div class="form-group">
                                    <label for="firstName">First Name</label>
                                    <input type="text" name="txtFirstName"  class="form-control" id="inputFirstName" placeholder="First Name">
                                </div>
                                <div class="form-group">
                                    <label for="lastName">Last Name</label>
                                    <input type="text" name="txtLastName" class="form-control" id="inputLastName" placeholder="First Name">
                                </div>
                                <div class="form-group">
                                    <label for="emailAddress">Email address</label>
                                    <input type="email" name="txtEmail" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
                                    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
                                </div>
                                <div class="form-group">
                                    <label for="password">Password</label>
                                    <input type="password" name="txtPassword" class="form-control" id="exampleInputPassword1" placeholder="Password">
                                </div>
                                <div class="form-group">
                                    <label for="Dob">Date of birth:</label>
                                    <input type="date" name="DoB" class="form-control" id="inputDOB" placeholder="First Name">
                                </div>
                                <div class="form-group">
                                    <label for="Address1">Address1</label>
                                    <input type="text" name="txtAddress1" class="form-control" id="inputAddress1" placeholder="First Name">
                                </div>
                                <div class="form-group">
                                    <label for="Address2">Address2</label>
                                    <input type="text" name="txtAddress2" class="form-control" id="inputAddress2" placeholder="First Name">
                                </div>
                                <div class="form-group">
                                    <label for="postcode">Postcode</label>
                                    <input type="text" name="txtPostcode" class="form-control" id="inputPostcode" placeholder="First Name">
                                </div>
                                <input type="submit" value="Submit" name="taxSubmit"  />
                            </form>

                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                    </div>

                </div>
            </div>

        </div>

    </body>
</html>

你有什么错误吗?@JosanIracheta没有错误,我在表单中输入的数据不会发布到数据库中。当我手动转到insertrecord.php时,它确实可以工作,因为它只向数据库中插入空白数据。您没有连接或查询失败。查看mysql_错误:1确保您获得了信息。在insertRecord.php中,添加一个print\u r$\u POST;并确保从表单中获取字段。2然后调试插入。再次打印您的查询并确保它是正确的。您可以打印查询并手动运行以进行验证。3然后你看你的PHP插入代码。@Nic3500也许我不是很具体,问题是当我在表单中输入数据并按下提交按钮时,实际上什么都没有发生,数据保留在那里,我检查了错误,它连接了所有的东西,只是当我按下提交按钮时,什么都没有发生。我没有收到任何错误,因为真正的问题是当我按下提交按钮时,表单中的数据没有发生任何事,数据没有发送到任何地方,也没有任何更改,就像它没有发布到数据库或其他什么。我运行了错误检查,没有任何更改。您是否执行了echo$query;确保脚本发布了数据?例如:与此类似的输出:在Userinfo FirstName、LastName、Email、Password、Dob、Address1、Address2、Postcode值“JHON”、“DOE”中插入mail@mail.com“,”ssss“,”1986-11-01“,”ADDR1“,”ADDR2“,”999“没有回显$query;什么也没发生,它没有运行insertRecord.php,我输入表单的数据就停留在那里,提交按钮不起作用。