【问题标题】:Append Select List value to URL将选择列表值附加到 URL
【发布时间】:2013-11-08 19:04:26
【问题描述】:

我有一个表单,它只不过是一个选择列表,它显示来自数据库的记录和一个按钮。我要做的就是当他们选择一个选项并单击提交时,它会将他们带到一个删除相关记录的页面。要删除它 - 我需要将 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>

【问题讨论】:

    标签: html forms url append selectlist


    【解决方案1】:

    错误在于编码结构。

    我在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>
    

    它应该根据需要将form 中的信息(list-value)附加到 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-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2019-04-01
      • 2022-01-17
      • 2014-02-14
      • 2012-03-15
      相关资源
      最近更新 更多