【发布时间】:2026-02-01 20:15:02
【问题描述】:
我正在使用 php 和 mysql 构建一个巴士预订系统。 在这里,我尝试输入搜索字段“路由”,它是 mysql 表的字段。 在搜索结果并将结果打印到页面时似乎有问题。请帮帮我。
<?php
$connect=mysqli_connect("localhost","root","","tsms");
$output ='';
if(isset($_POST['from'])){
$searchq = $_POST['from'];
$query = mysqli_query("SELECT * FROM bus WHERE route='$serchq' ");
$count = mysqli_num_rows($query);
if($count==0){
echo "<script>
alert('No bus services are found');
</script>";
} else {
while($row = mysqli_fetch_array($query)){
$imageData = $row['image'];
$arrival = $row['arrival_time'];
$departure = $row['departure_time'];
$type = $row['bus_type'];
$class = $row['class'];
$name = $row['bus_name'];
$facilities = $row['facilities'];
$reservation = $row['reservation_fee'];
$output = '<div>'.$arrival.''.$departure.''.$type.''.$class.''.$name.''.$facilities.''.$reservation.'</div>';
}
}
}
echo $output;
?>
【问题讨论】:
-
搜索和打印好像有问题 能说的具体点吗?顺便说一句,您的问题很有可能被 sql 注入。
-
你说的是下拉搜索吗..
-
它没有显示任何结果。也没有错误。