0

我有一个表单,它只不过是一个选择列表,它显示来自数据库的记录和一个按钮。我要做的就是当他们选择一个选项并单击提交时,它会将他们带到一个删除相关记录的页面。要删除它 - 我需要将 tech_id(来自选择列表)附加到 URL。我已经按照使用文本字段的方式完成了它,但这不起作用。有什么建议么?

<form method="post" id="form1" name="form1" action="delete-tech.php?tech_id=<?php echo $_POST['technician']; ?>">
  <p>Choose Technician to Delete:
    <select name="technician" id="technician" title="technician">
      <?php
do {  
?>
      <option value="<?php echo $row_getTechs['tech_id']?>"><?php echo $row_getTechs['tech_name']?></option>
      <?php
} while ($row_getTechs = mysqli_fetch_assoc($getTechs));
  $rows = mysqli_num_rows($getTechs);
  if($rows > 0) {
      mysqli_data_seek($getTechs, 0);
      $row_getTechs = mysqli_fetch_assoc($getTechs);
  }
?>
    </select>
  </p>
  <p>
    <input name="submit" type="submit" id="submit" value="Delete Technician">
  </p>
</form>
4

1 回答 1

0

错误在于编码结构。

我稍微改变了以下while语句的代码段的位置(即放在do短语之前):

<form method="GET" id="form1" name="form1" action="delete-tech.php">
  <p>Choose Technician to Delete:
    <select name="technician" id="technician" title="technician">
    <?php
      $rows = mysqli_num_rows($getTechs);
      if($rows > 0) {
          mysqli_data_seek($getTechs, 0);
          $row_getTechs = mysqli_fetch_assoc($getTechs);
          do {  
    ?>
      <option value="<?php echo $row_getTechs['tech_id']?>"><?php echo $row_getTechs['tech_name']?></option>
    <?php
          }while ($row_getTechs = mysqli_fetch_assoc($getTechs));
      }
    ?>
    </select>
  </p>
  <p>
    <input name="submit" type="submit" id="submit" value="Delete Technician">
  </p>
</form>

它应该根据需要将信息(列表值)从URL附加form到 URL。看看这个。

正如您所说,它不起作用还有另一种使用JavaScript的方法:

<form method="post" id="form1" name="form1" action="delete-tech.php">
  <p>Choose Technician to Delete:
    <select name="technician" id="technician" title="technician">
    <?php
      $rows = mysqli_num_rows($getTechs);
      if($rows > 0) {
          mysqli_data_seek($getTechs, 0);
          $row_getTechs = mysqli_fetch_assoc($getTechs);
          do {  
    ?>
      <option value="<?php echo $row_getTechs['tech_id']?>"><?php echo $row_getTechs['tech_name']?></option>
    <?php
          }while ($row_getTechs = mysqli_fetch_assoc($getTechs));
      }
    ?>
    </select>
  </p>
  <p>
    <input name="submit" type="button" id="submit" value="Delete Technician" onclick="location.href='delete-tech.php?tech_id='+document.getElementById('technician').value">
  </p>
</form>
于 2013-10-29T15:39:13.243 回答