我已经创建了一个搜索页面,但无论我如何更改它,即使它们与数据库完美匹配,也无法返回结果。有人可能是另一双眼睛并指出我正确的方向吗?
我总是不确定将变量放在SQL语句中,所以可能是错误。
Searchform.php
<?php
include 'index.php';
?>
<html>
<center>
<link rel="stylesheet" type="text/css" href="skeleton.css" />
<link rel="stylesheet" type="text/css" href="normalize.css" />
<title>Search</title>
<h3>Search People</h3>
<p>You may search either by first or last name</p>
<form method="post" action="search.php" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
</html>
</p>
</center>
的search.php
<?php
include 'pagetemplate.php';
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){
$name=$_POST['name'];
//-query the database table
$result = $mysqli_conn->query("SELECT * FROM users WHERE FirstName LIKE '%$name%' OR LastName LIKE '%$name%'");
print " Query returned ". $result->num_rows . " rows ";
//The function to display data is below
displayData($result);
// $stmt = mysqli_prepare($con, 'SELECT * FROM users WHERE (FirstName LIKE ? OR LastName LIKE ? OR Username LIKE ?)';
//mysqli_stmt_bind_param($stmt, 'sss', "%$name%", "%$name%", "%$name%");
//mysqli_stmt_execute($stmt);
//-run the query against the mysql query function
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>