gpt4 book ai didi

php - 帖子的具体输入

转载 作者:行者123 更新时间:2023-11-29 17:44:09 24 4
gpt4 key购买 nike

我想创建可以从数据库检索数据的 PHP 页面,但例如,当用户输入 15 岁年龄并选择类别“男性”时,则会显示男性和女性的数据。我怎样才能让它更具体,只是男性对男性,女性对女性,男性和 child 对男性和 child 等等? `

<?php
// check if the form has been submitted and display the results
if(isset($_POST["Age"]) && isset($_POST["Categories"])){
define('DB_NAME', 'test');
define('DB_USER', 'test');
define('DB_PASSWORD', 'test');
define('DB_HOST', 'localhost');
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$conn){die('Could not connect: ' . mysqli_connect_error());}
// escape the post data to prevent injection attacks
$Age = mysqli_real_escape_string($conn, $_POST['Age']);
$Categories = mysqli_real_escape_string($conn, $_POST['Categories']);
$sql = "SELECT * FROM `Medic Rate` WHERE `Age` LIKE '%$Age%' AND `Categories` LIKE '%$Categories%'";
$result=mysqli_query($conn, $sql);
// check if the query returned a result
if(!$result){echo 'There are no results for your search';}
else{
// result to output the table
echo '<table class="table table-striped table-bordered table-hover">';
echo "<tr>
<th>Medic_Id</th>
<th>Age</th>
<th>Categories</th>
<th>Plan</th>
<th>Rate</th>
</tr>";
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo "<tr><td>";
echo $row['Medic_Id'];
echo "</td><td>";
echo $row['Age'];
echo "</td><td>";
echo $row['Categories'];
echo "</td><td>";
echo $row['Plan'];
echo "</td><td>";
echo $row['Rate'];
echo "</td></tr>";
}
echo "</table>";
}
mysqli_close($conn);
} // end submitted
else{// not submitted to output the form
?>
<form action=" " method="post">
<label>Enter Age:</label>
<input name="Age" type="number" placeholder="Type Here"><br><br>
<label>Enter Categories:</label>
<select name="Categories" />
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Male & Child">Male & Child</option>
<option value="Female & Child">Female & Child</option>
<option value="Insured & Spouse">Insured & Spouse</option>
<option value="Insured & Family">Insured & Family</option>
</select><br><br>
<input type="submit" value="Enter">
</form>
<?php } // end not submitted?>`

最佳答案

尝试改变<select name="Categories" /><select name="Categories">删除反斜杠并删除脚本末尾的反勾号。

关于php - 帖子的具体输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49875252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com