我正在尝试在我的网站中编写搜索功能,但是连接$ sql语句并获取结果不起作用,我不知道他们为什么不工作,因为我不擅长预备语句。
include("db.php");
if(isset($_GET["city"])&&isset($_GET["term"])){
$sql = "SELECT * FROM markers WHERE (city= ? name LIKE ? OR discrip LIKE ?)";
echo $sql;
$stmt = $con->prepare($sql);
$c = "'%". $_GET['city'] . "%'";
$t = "'%". $_GET['term'] . "%'";
$term = str_replace(",", " ", $t);
$city = str_replace(",", " ", $c);
$stmt->bind_param("sss", $city, $term, $term);
$stmt->execute();
while($row = $stmt->fetch_array(MYSQLI_ASSOC)){
$name = $row["name"];
$add = $row["address"];
$phone = $row["phonenum"];
}
}
?>