我有一个页面从我的 mysql 数据库加载数据并正确显示数据,但在尝试实现搜索功能后,现在尝试加载页面时出现错误。
下面是我为搜索栏添加的 html 代码(位于 PhysicianSearch.php 文件中):
<form action="PhysicianSearch.php" method="post">
<input type="text" placeholder="Search.." name="ValueToSearch">
<input type="submit" name="search" value="Filter"><br><br>
</form>
下面是我为搜索栏添加的 php 代码(位于文件 PhysicianSearch.php 中):
<?php
if(isset($_POST['search'])) {
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM Physician WHERE CONCAT('physicianID', 'firstName', 'lastName', 'yearNum', 'yearNum', 'position', 'isAttending', 'highRiskTrained') LIKE '%" . $valueToSearch ."%'";
$search_result = filterTable($query);
} else {
$query = "select * from Physician";
$search_result = filterTable($query);
}
function filterTable($query) {
$connect = mysqli_connect("localhost", "root", "password", "dbName");
$filter_results = mysqli_query($connect, $query);
return $filter_results
}
?>
最佳答案
您的输入
名称是ValueToSearch
,其中PHP代码正在检查valueToSearch
确保它们具有相同的外壳
关于PHP 搜索栏导致页面加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48548207/