简体   繁体   English

如何从输入中获取价值并将其用于PHP查询中?

[英]How can I get value from input and use it in query in PHP?

I want to show in option values that datas where the id equal to the role ID. 我想在选项值中显示ID等于角色ID的数据。 For example the Role1 has classification1 and classification2 and in this case it just show the classification1 and classification2 in the option value. 例如,Role1具有分类1和分类2,在这种情况下,它仅在选项值中显示了分类1和分类2。 My problem is that if I get the ID (It's in the input), then I write the query, the option value is empty, but in the text field, the ID is good. 我的问题是,如果我获得ID(在输入中),那么我编写查询,选项值是空的,但是在文本字段中,ID很好。 I fetch the data's id in another PHP file to the input. 我在另一个PHP文件中将数据的ID提取到输入中。 How can I solve this to show the classifications where the id equal to the input value? 如何解决此问题以显示ID等于输入值的分类?

index.php 的index.php

<?php
$id = $_POST["RoleID"];

$testQuery = $conn->prepare("SELECT classification.class_id AS id, classification.name AS name
    FROM classification
    INNER JOIN role_classification ON classification.class_id = role_classification.class_id
    WHERE role_classification.role_id = ?");
$testQuery->bind_param("i", $id);
$testQuery->execute();
$testResult = $testQuery->get_result();
$testQuery->close();
?>

<form method="post" id="insert_form"> 
   <select name="classification[]" id="classification" multiple>
      <?php 
      while($row = $testResult->fetch_array()) {
      ?>
      <option value="<?php echo $row['id'];?>"><?php echo $row['name'];?></option>
      <?php
      }
      ?> 
   </select>
   <input type="hidden" name="RoleID" id="RoleID" /> 
</form>

Add a value to your input : <input type="hidden" name="RoleID" id="RoleID" value=" "/> 在输入中添加一个值: <input type="hidden" name="RoleID" id="RoleID" value=" "/>

It may be <input type="hidden" name="RoleID" id="RoleID" value="<?php echo $row['id'];?"/> 可能是<input type="hidden" name="RoleID" id="RoleID" value="<?php echo $row['id'];?"/>

暂无
暂无

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

相关问题 如何从另一个PHP文件获取输入值? - How can I get the input value, from another PHP file? 如何使用php从MySQL查询中获取索引值? - How can i get the index value from the MySQL query with php? (PHP)如何使输入隐藏数据从输入框中获取价值 - (PHP) How can I make input hidden data to get value from input box 当我在基于条件的查询中使用if else条件时,如何在PHP CODEIGNITER中的视图上获取该值 - When i use if else condition in query based on condition, how can i get that value on view in PHP CODEIGNITER 如何从输入复选框获取值以在查询中使用它来显示信息 - How to GET value from an input checkbox to use it in a query to show information 如何在php变量中获取sql查询的int值? 所以我以后可以用php变量来计算 - How can i get a int value of a sql query in a php variable ? So i can later use it calculate with php variables 如何存储从 isset($_GET['Something']) 获得的值以在 .php 页面中重复使用 - How can I store the value I get from the isset($_GET['Something']) for repeated use within the .php page php curl如何获取输入值? - How i can get input value with php curl? 如何从自动完成中获得单击的输入单选值以将表单发送到 php 文件 - How can I get clicked input radio value from autocomplete to send in form to php file 如何从数据库中获取值,并在输入字段中使用和显示它? - How can I get a Value from my Database and use and show it inside an Input Field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM