php - 提交按钮在 while 循环之外,但在提交表单后它总是四处移动

标签 php html css

我正在尝试创建一个联系表单,并且该表单本身可以正常工作,但每次我提交回复消息时,提交按钮都会移出位置。虽然我已将提交按钮放在 while 循环之外,但它仍然像在 while 循环内一样运行

我试着在这个地方移动我的括号,但似乎没有任何效果。我正在考虑使用固定位置,但我仍然认为我应该能够让它与绝对或相对一起工作。我将它更改为 relative 但按钮没有显示位置 relative

这是我的主要代码:

<?php
include_once 'navbar.php';
if(!isset($_SESSION['u_uid'])) {
    header("Location: index.php?medical_premium_users=notlogin");
    exit();
} else {
    include_once 'includes/dbh.php';

    $sql = "SELECT * FROM contact_form;";

    $stmt = mysqli_stmt_init($conn);
                        if(!mysqli_stmt_prepare($stmt, $sql)) {
                           echo "SQL error";
                        } else {


                          mysqli_stmt_execute($stmt);
                          $result = mysqli_stmt_get_result($stmt);
                          $resultCheck = mysqli_num_rows($result);

                          if ($resultCheck < 1) {
                              echo '<div class="no_enquiries">There are no enquiries yet!</div>';
                          }
                          echo '<form action="medical_enquiries_reply_process.php" method="POST">
                          <table class="medical_enquiries_reply">
                      <tr>
                      <th colspan="3" class="update_title">Welcome to the Administrator\'s Enquiries Reply Section</th>
                      </tr>';

                      while ($row = mysqli_fetch_assoc($result)) {
                        echo '<tr><th>Ticket:</th><td>'.$row['ticket'].'<input type="hidden" name="ticket" value="',htmlspecialchars($row['ticket']),'"></td></tr>
                               <tr><th>Username:</th><td>'.$row['user_uid'].'</td></tr>
                               <tr><th>First Name:</th><td>'.$row['first_name'].'</td></tr>
                               <tr><th>Last Name:</th><td>'.$row['last_name'].'</td></tr>
                               <tr><th>E-Mail:</th><td>'.$row['email'].'</td></tr>
                               <tr><th>Subject:</th><td>'.$row['subject'].'<input type="hidden" name="subject" value="',htmlspecialchars($row['subject']),'"></td></tr>
                               <tr><th>Message:</th><td>'.$row['message'].'</td></tr>
                               <tr><th>Date of Message:</th><td>'.$row['date_sent'].'</td></tr>
                               <tr><th>Message Reply:</th><td>'.$row['message_reply'].'</td></tr>
                               <tr><th>Date of Reply:</th><td>'.$row['date_reply'].'</td></tr>
                               <tr><th>Solved Status:</th><td>'.$row['solved'].'</td></tr>';
                      }




                     echo '</tr>
                        <th>Reply Section</th><td class="reply"><textarea name="reply" placeholder="Message Reply"></textarea></td>
                      </tr>
                       <tr>
                      <th>Has this been resolved?</th><td colspan="2"><input type="radio" name="resolve" value="No"><label id="no">No</label><input type="radio" name="resolve" value="Yes"><label id="yes">Yes</label></td>
                      </tr>
                       <tr>
                      <th>Reply</th><td colspan="2"><input type="submit" name="submit" value="Reply"></td>
                      </tr>
                      </table>
                      </form>';


                        }
}











?>

This is my CSS code:

.medical_enquiries_reply input[type="submit"] {
   position: relative;
   top: 346em;
   left: 41em;
   width: 10%;
   height: 40px;
   border:none;
   background-color: #222;
   font-family: arial;
   font-size: 16px;
   color: #fff;
   cursor:pointer;
   border-radius: 1em;
   white-space: nowrap;
}

最佳答案

把这一行的th改成td

<th>Reply</th><td colspan="2"><input type="submit" name="submit" value="Reply"></td>

以及所有其他以 th 开头并以 td 结尾的行 lol

TH 仅用于表头,应由对应的标签结束。

表结构应该是这样的

<table>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>

看看第一个 tr 如何包含 th 而所有其他都是 td?

您面临的问题是由您的 HTML 结构引起的。浏览器没有关闭标签并建立了一个奇怪的表格。由于标签没有正确关闭,它试图通过自己关闭标签来渲染 View ,但他没有在正确的地方关闭它们。

我还注意到您的 HTML 中有额外的 TR 结束标记

enter image description here

第一个应该是一个tr开头

所以工作表看起来像这样:

<form action="medical_enquiries_reply_process.php" method="POST">
    <table class="medical_enquiries_reply">
        <tr>
            <th colspan="3" class="update_title">Welcome to the Administrator\'s Enquiries Reply Section</td>
        </tr>
        <tr><td>Ticket:</td><td>'.$row['ticket'].'<input type="hidden" name="ticket" value="',htmlspecialchars($row['ticket']),'"></td></tr>
        <tr><td>Username:</td><td>'.$row['user_uid'].'</td></tr>
        <tr><td>First Name:</td><td>'.$row['first_name'].'</td></tr>
        <tr><td>Last Name:</td><td>'.$row['last_name'].'</td></tr>
        <tr><td>E-Mail:</td><td>'.$row['email'].'</td></tr>
        <tr><td>Subject:</td><td>'.$row['subject'].'<input type="hidden" name="subject" value="',htmlspecialchars($row['subject']),'"></td></tr>
        <tr><td>Message:</td><td>'.$row['message'].'</td></tr>
        <tr><td>Date of Message:</td><td>'.$row['date_sent'].'</td></tr>
        <tr><td>Message Reply:</td><td>'.$row['message_reply'].'</td></tr>
        <tr><td>Date of Reply:</td><td>'.$row['date_reply'].'</td></tr>
        <tr><td>Solved Status:</td><td>'.$row['solved'].'</td></tr>
        <tr>
            <td>Reply Section</td><td class="reply"><textarea name="reply" placeholder="Message Reply"></textarea></td>
        </tr>
        <tr>
            <td>Has this been resolved?</td><td colspan="2"><input type="radio" name="resolve" value="No"><label id="no">No</label><input type="radio" name="resolve" value="Yes"><label id="yes">Yes</label></td>
        </tr>
        <tr>
            <td>Reply</td><td colspan="2"><input type="submit" name="submit" value="Reply"></td>
        </tr>
    </table>
</form>

关于php - 提交按钮在 while 循环之外,但在提交表单后它总是四处移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54023490/

相关文章:

javascript - 分机号 : createStyleSheet problems with two classes

javascript - 当其他图表类型正确定位时,为什么我的圆环图位于容器外部?

php - mySQL重复键多次更新

html - 如何修复链接上的边框和填充

php - 表中带有子类别的类别 - PHP + MYSQL

javascript - 是否有一个 xmpp 客户端可以在页面刷新时保持聊天?

javascript - 使用 javascript 打印带有文本字段的 div 内容时遇到问题?

html - 缩略图图像大小不起作用

php - 通过 AJAX 传递数据的空 POST

php - 关于定期任务