如何在PHP中的表行中添加注释

时间:2018-03-05 03:52:18

标签: php html mysql

我有约会表&当用户在文本框中键入并单击“提交”时,需要在表中添加注释列,以便更新注释。我已经尝试了下面的代码,但无法理解为什么它不能正常运行。我已经对此进行了大量的研究,但在路障之后遇到了障碍,所以我非常希望你能帮助我,非常感谢! Here is an img of the app table 这是我的代码:

<!--    <form method="post" action="delete.php" >   --> 
          <form method="post" action="tea_appview.php">  

       <table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
            <!--      <table cellpadding="0" cellspacing="0" border="0" class="table table-bordered" id="example">  -->
                    <thead>
                          <tr>
                                <th>appoinment ID</th>
                                <th>Date</th>
                                <th>time</th>
                                <th>subject</th>
                                <th>Appointment from [parent]</th>
                                <th>Appointment to (teacher) </th>
                                <th> accept/reject </th>
                                <th>state</th>
                                <th>comm</th>
                          </tr>
                   </thead>
                   <tbody>
                        <?php 
                            $query=mysqli_query($conn, "select * from `app` left join `par` on par.par_id=app.par_id
                            left join `tea` on tea.tea_id=app.tea_id
                            ORDER BY app_id DESC"); 

                        if($query === false)
                                {
                                    throw new Exception(mysqli_error($conn));
                                }
                                while($row=mysqli_fetch_array($query))
                                {
                                    $ann_id=$row['app_id'];
                                    $date=$row['date'];
                                    $msg=$row['time'];

                                    $username = $row['username'];
                                     $username = $row['p_username'];
                                     $sub = $row['sub'];
                        ?>
                <tr>
                    <td><?php echo $row['app_id'] ?></td>
                    <td> <?php echo date('j/m/y',strtotime($row['date'])); ?></td>
                    <td><?php echo $row['time'] ?></td>
                    <td><?php echo $row['sub'] ?></td>
                    <td><?php echo $row['p_username'] ?></td>
                    <td><?php echo $row['username'] ?></td>

                    <td>
                       <a href="tea_appview.php?app_id=<?php echo $row['app_id'] . "&" . "state=reject";?>" class="reject">reject</a>
                        <a href="tea_appview.php?app_id=<?php echo $row['app_id'] . "&" . "state=accept";?>" class="accept">accept</a> 
                    </td>
                    <td><?php echo $row['state'] ?></td>


                <td><input type="text" name="comm">
                    <input type="submit" name="submit" value="submit">
                </td>  
                </tr>

                        <?php  
                            //---------PROBLEM IS HERE-----------------------
                            //if(isset($_GET['app_id'], $_POST['submit'])!="")
                            if(isset($_GET['app_id']) && $_POST['submit'] !="")
                            {
                                $stmt = mysqli_prepare($conn, "UPDATE app SET comm = ? WHERE app_id = ?");
                                mysqli_stmt_bind_param($stmt, "sd", $_GET['comm'], $_GET['app_id']);
                                $stmt->execute();
                                $stmt->close();
                            }
                            //-------------------------------
                            if (isset($_GET['state'], $_GET['app_id']))
                            {
                                $stmt = mysqli_prepare($conn, "UPDATE app SET state = ? WHERE app_id = ?");
                                mysqli_stmt_bind_param($stmt, "sd", $_GET['state'], $_GET['app_id']);
                                $stmt->execute();
                                $stmt->close();
                            }



                      }

                       ?>

                  </tbody>
              </table>
         </div>
      </form>

1 个答案:

答案 0 :(得分:1)

问题出在您的表单标记

<form method="post" action="file.php?app_id=VALUE&state=VALUE">  

您必须使用处理代码的文件和$_GET参数中的变量来填写您的操作。另请查看

if(isset($_GET['app_id']) && $_POST['submit'] !="")