脚本页面运行良好。当我在下一个仪表板页面中选择多个选项时,没有显示任何记录。请解决这个问题。我认为所选值无法在仪表板页面中识别
脚本.php
<?php include("connection.php") ?>
<form id="script" name="script" action="dashboard.php" method="post">
<strong>Choose Script Name : </strong><select name="script[]" id="select3" multiple=multiple style="margin: 20px;width:300px;">
<?php
$result = $conn->query("select script_name from script_details ORDER BY script_name");
while ($row = $result->fetch_assoc()) {
unset($script_name);
$script_name = $row['script_name'];
echo '<option value="' . $id . '">' . $script_name . '</option>'; // Generated From database
}
?>
</select>
<input type="submit" name="submit" id="button" value="View Dashboard" />
</form>
Dashboard.php
<table border="1">
<tr align="center">
<th>Number </th> <th>Script Name</th> <th> Date</th>
</tr>
<?php
include("connection.php");
$select = $_POST['script'];
$selects = "SELECT * FROM script_details where script_name='$select'";
$result = $conn->query($selects);
echo "<table>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"] . "</td><td>" . $row["script_name"] . "</td></tr>" . "</td><td>" . $row["date"] . "</td></tr>";
}
echo "</table>";
[This is script page Image. Selecting option from script_details database. Field name : script_name.][1]?>
最佳答案
Firstof all your code is sql vulnerable
在 Scrip 中,您没有在 <select>
中定义选项值标签。首先定义值,为此您需要从数据库获取
脚本.php
<?php include("connection.php") ?>
<form id="script" name="script" action="dashboard.php" method="post">
<strong>Choose Script Name : </strong>
<select name="script[]" id="select3" multiple=multiple style="margin: 20px;width:300px;">
<?php
$result = $conn->query("select id, script_name from script_details ORDER BY script_name");
while ($row = $result->fetch_assoc()) {
unset($script_name);
$script_name = $row['script_name'];
$id = $row['id'];
echo '<option value="' . $id . '">' . $script_name . '</option>'; // Generated From database
}
?>
</select>
<input type="submit" name="submit" id="button" value="View Dashboard" />
</form>
在仪表板中进行适当的标记
Dashboard.php
<table border="1">
<tr align="center">
<th>Number </th> <th>Script Name</th> <th> Date</th>
</tr>
<?php
include("connection.php");
$select = $_POST['script'];
$ids = "'" . implode("','", $select) . "'";
$selects = "SELECT * FROM script_details WHERE id IN ($ids)";
$result = $conn->query($selects);
while ($row = $result->fetch_assoc()) {
echo "<tr>"
. "<td>" . $row["id"] . "</td>"
. "<td>" . $row["script_name"] . "</td>"
. "<td>" . $row["date"] . "</td>"
. "</tr>";
}
?>
</table>
关于php - 使用 PHP Mysqli 从下拉列表中选择多个选项时如何显示数据库中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44904627/