PHP搜索栏导致页面加载错误

时间:2018-01-31 17:34:26

标签: php html mysql

我有一个页面从我的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

  }
?>

1 个答案:

答案 0 :(得分:1)

您的input名称为ValueToSearch,其中PHP代码正在检查valueToSearch

确保他们有相同的案例