[英]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等于输入值的分类?
<?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.