Php 网站上的搜索功能-不显示任何数据
我已经创建了一个搜索页面,但无论我如何更改它,我都无法让它返回结果,即使它们与数据库完全匹配。也许有人能成为另一双眼睛,为我指出正确的方向吗 在SQL语句中放入变量时,我总是很不确定,所以可能是错误 Searchform.phpPhp 网站上的搜索功能-不显示任何数据,php,html,sql,search,Php,Html,Sql,Search,我已经创建了一个搜索页面,但无论我如何更改它,我都无法让它返回结果,即使它们与数据库完全匹配。也许有人能成为另一双眼睛,为我指出正确的方向吗 在SQL语句中放入变量时,我总是很不确定,所以可能是错误 Searchform.php <?php include 'index.php'; ?> <html> <center> <link rel="stylesheet" type="text/css" href="skeleton.css" /> <
<?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>
<?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>";
}
}
}
?>
搜寻
搜身
您可以按名字或姓氏搜索
Search.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>
<?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>";
}
}
}
?>
能否尝试更改:-$result=$mysqli\u conn->query(“从名为“%$name%”或姓为“%$name%”的用户中选择*”代码>这个到这个<代码>$result=$mysqli_conn->query('SELECT*来自FirstName(如“%$name%”)或LastName(如“%$name%”)的用户)代码>仍然显示空白页!我以“abc”为例,将一些数据和所有abc一起输入数据库。我想不出来!如果我使用我在下面写的注释掉的OO代码,我将如何显示它?这是我没有将那部分代码用作未完成代码的唯一原因。你能给出搜索表单的源代码吗?你确定脚本肯定会被调用吗?它的执行路径是什么。我把echo
s放得到处都是。