繁体   English   中英

如何在PHP中将按钮ID从一页传递到另一页

[英]how to pass the button id from one page to another page in php

我已经在我的php代码中创建了动态按钮,我需要将该创建的动态按钮ID转到php中的另一个页面,以从数据库中获取值。

我需要将该按钮的点击ID传递给SQL QUERY。
我如何在下面的代码创建动态按钮代码时传递值?

<?php
function dash()
{
  include 'config.php';
  $sql = "SELECT  RoomNumber  FROM roommaster ";
  if ($result = mysqli_query($db, $sql)) {
    $str = '';
    while ($row = mysqli_fetch_array($result)) {
      // generate array from comma delimited list
      $rooms = explode(',', $row['RoomNumber']);
      //create the dynamic button and set the value
      foreach ($rooms as $v) {
        $str .= "<input type='button'  name='b1' id='btn' value='" . $v . "' />";
      }
    }
    return $str;
  } else {
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
  }
  mysqli_close($db);
}
?>

<!Doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <title>room boking</title>

  <link href="css/bootstrap1.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/front.css">
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

</head>

<body>
  <form mathod="post" action="booking.php">
    <div class="  row box col-md-4">
      <div style="color:black">
        <?php echo dash();?>
      </div>
    </div>


  </form>


</body>

</html>

您可以在隐藏的输入类型内发送id值,如下所示:

<input type="hidden" value="btn" name="buttonID">

在booking.php中,使用$_POST['b1'] (其中b1是输入的名称)来获取与任何其他表单输入相同的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM