使用Bootstrap Modal工作的{更新行}

时间:2016-04-06 14:24:20

标签: javascript php jquery mysqli bootstrap-modal

我需要使用Bootstrap模式更新我的表。行数据已成功传递到模式窗体,但UPDATE查询不起作用。我究竟做错了什么?或者有没有其他方法可以将数据传递给模态表单,以便我可以更新行?

这是我的编辑按钮:

<a class="btn btn-primary btn-xs" data-toggle="modal" data-target="#editBox" href="file.php?id=<?php echo $row_selectDept['dept_id']; ?>"><i class="fa fa-pencil"></i></a>

虽然这是我的file.php

<?php
include("../includes/config.php");
$reqErr = "";
$id = $_GET["id"]; //escape the string if you like
$query_selectDeptDetails = "SELECT * FROM department WHERE dept_id='$id'";
$result_selectDeptDetails = mysqli_query($con,$query_selectDeptDetails);
$row_selectDeptDetails = mysqli_fetch_array($result_selectDeptDetails);
$dept_name = $dept_code = "";
if($_SERVER['REQUEST_METHOD'] == "POST") {
  if(!empty($_POST['dept_name'])) {
    $dept_name = $_POST['dept_name'];
  }
  if(!empty($_POST['dept_code'])) {
    $dept_code = $_POST['dept_code'];
  }
  if($dept_name != null) {
    $query_UpdateDept = "UPDATE department SET dept_name='$dept_name',dept_code='$dept_code' WHERE dept_id='$id'";
    if(mysqli_query($con,$query_UpdateDept)) {
      $reqErr = '<div class="alert alert-success" id="myAlert">
            <a href="" class="close"> &nbsp;  <i class="fa fa-times"></i></a>
          <i class="fa fa-check-circle"></i> Department updated</div>';
    }
    else {
      $reqErr = '<div class="alert alert-danger" id="myAlert">
            <a href="" class="close"> &nbsp;  <i class="fa fa-times"></i></a>
          <i class="fa fa-exclamation-circle"></i> Failed to update Department</div>';
    }
  }
}
?>

<script src="../assets/js/custom-scripts.js"></script>
<script src="../js/jquery.validate.min.js"></script>
<?php echo $reqErr; ?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Update Department</h4>
</div>
<div class="modal-body">
  <form action="" method="POST" class="form" id="add-department">
    <div class="form-group">
      <input type="text" class="form-control" id="dept_name" name="dept_name" placeholder="Department Name" value="<?php echo $row_selectDeptDetails['dept_name']; ?>"/>
      <span class="help-block"></span>
      </div>
    <div class="form-group">
      <input type="text" class="form-control" id="dept_code" name="dept_code" placeholder="Department Code" value="<?php echo $row_selectDeptDetails['dept_code']; ?>"/>
      <span class="help-block"></span>
      </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      <input type="submit" id="submit_btn" class="btn btn-primary" />
    </div>
</form>
</div>

这就是模态内容的所在:

<div class="modal fade" id="editBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
        </div>
    </div>
</div>

0 个答案:

没有答案