使用bootstrap模式在php mysqli上添加数据

时间:2015-12-02 15:10:51

标签: php twitter-bootstrap mysqli

如果我尝试将它们分开,则模态窗口不会出现。 如果我尝试将它们组合起来,模态会出现但不会起作用。

Twitter-bootstrap代码:

<?php
include "config.php";
?>

<div class="modal fade" id="userModal" 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">Create New Entry</h4>
          </div>
          <div class="modal-body">

          <form class="form-horizontal"method="post" action="adduser.php">
            <fieldset>

              <div class="form-group">
              <label for="inputuName" class="col-sm-6 control-label">Username</label>
              <div class="col-sm-6">
              <input type="text" class="form-control" id="inputuName" name="inputuName" placeholder="Username" required>
              </div>
              </div>

              <div class="form-group">
              <label for="inputPword" class="col-sm-6 control-label">Password</label>
              <div class="col-sm-6">
              <input type="text" class="form-control" id="inputPword" name="inputPword" placeholder="Password" required>
              </div>
              </div>

             <div class="form-group">
              <label for="inputfName" class="col-sm-6 control-label">First Name</label>
              <div class="col-sm-6">
              <input type="text" class="form-control" id="inputfName" name="inputfName" placeholder="First Name" required>
              </div>
              </div>

              <div class="form-group">
              <label for="inputlName" class="col-sm-6 control-label">Last Name</label>
              <div class="col-sm-6">
              <input type="text" class="form-control" id="inputlName" name="inputlName" placeholder="Last Name" required>
              </div>
              </div>

             <div class="form-group">
              <label for="inputAddress" class="col-sm-6 control-label">Address</label>
              <div class="col-sm-6">
              <textarea class="form-control" rows="3" id="inputAddress" name="inputAddress" placeholder="Address" required></textarea>
              </div>
              </div>

            <div class="form-group">
              <label for="acctType" class="col-sm-6 control-label">Account Type</label>
              <div class="col-sm-6">
                <select class="form-control" id="acctType" name="acctType" required>
                  <option>Admin</option>
                  <option>User</option>
                </select>
              </div>
            </div>

            </fieldset>
          </form>
          </div>
        <div class="modal-footer">
        <button type="create" name="create" class="btn btn-primary">Create</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
        </div>
      </div>
    </div>

添加其他用户的Php代码:

<?php
          if(isset($_POST['create'])){
            $un = $_POST['inputuName'];
            $pw = $_POST['inputPword'];
            $fn = $_POST['inputfName'];
            $ln = $_POST['inputlName'];
            $ad = $_POST['inputAddress'];
            $at = $_POST['acctType'];
          $query = $mysqli->query("INSERT INTO tbl_users VALUES('','$un','$pw','$fn','$ln','$ad','at')");
          if($query){
          ?>
          <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>Success!</strong> User data successfully added.
          </div>
          <?php
          } else{
          ?>
          <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>Danger!</strong> to Failed insert data.
          </div>
          <?php
          }
          }
          ?>

          <br/>

我已经将我的连接包含在页面的最顶部,看起来很有效,因为我可以看到表格中的数据......

0 个答案:

没有答案