单击“编辑”按钮时,必须在表单中填写相应的详细信息以进行编辑

时间:2018-04-07 17:53:19

标签: php jquery html css mysql

我有一个可以提交的表单,并且有列表,列出了所有提交的表单详细信息。 enter image description here

我以不同的方式尝试过它。我想在单击编辑按钮时填写表格并附上相应的详细信息。 这是我的php文件

<div class="row">

  <div class="col-sm-9">
    <b>Leader Name : </b><?php echo($row["lead_name"]); ?><br>
    <b>Phone Number : </b><?php echo($row["phone_number"]); ?><br>
    <b>Email : </b><?php echo($row["email"]); ?><br>
    <b>Part Created Time : </b><?php echo($row["create_date_and_time"]); ?>
    <br>
  </div>

  <div class="col-sm-3 ">

    <form role="form" action='index.php' method='POST'>
      <input type='hidden' name='party_id' value='<?php echo($row["party_id"]); ?> '>
      <input type="submit" class="btn btn-sm btn-success btn-block" id="edit" name="edit" value="Edit" style="font-size: 12px; padding: 3px;">
      <input type="submit" class="btn btn-sm btn-danger btn-block" id="delete" name="delete" value="Delete" style="font-size: 12px; padding: 3px;">
    </form>

    <?php
      if (isset($_POST['delete'])) {
        print("<script> alert('delete'); </script>");
        $party_id = isset($_POST['party_id']) ? $_POST['party_id'] : "";
        $queryDelete = "DELETE FROM party_details WHERE party_id='$party_id'";
        if ($conn->query($queryDelete)) {
          $_SESSION['party'] = "";
          $_SESSION['trips'] = [];
          print("<script>
            alert('Party removed');
            window.location.href='../tripCreate';
          </script>");
        } else { 
          print("<script>alert('Error when remove ! ');</script>");
        }
        $_POST = array();
      }

      if (isset($_POST['edit'])) {
        $party_id1 = isset($_POST['party_id']) ? $_POST['party_id'] : "";
        $query1 = "SELECT * FROM party_details WHERE party_id='$party_id1'";
        $result1 = $conn->query($query1);
        $row1 = $result1->fetch_assoc();
      }
    ?>
  </div>

1 个答案:

答案 0 :(得分:1)

首先,您不仅要指定想要实现的结果,还要指定您面临的问题类型。 它是php错误,还是未在结果页面中显示的信息?

我发现有一件事是你得到了$row1 = $result1->fetch_assoc();,但是在形式上你回复了$row[](而不是$row1[]),我看不到它在任何地方被创造出来。

另外,您是否在php中尝试var_dump($row)并检查其内容(或$row1 ...)?