我开发了一个页面,用户可以使用该页面搜索我的数据库中的各种数据,但不会显示任何内容。
不显示任何错误或消息,只是刷新页面。
bind_param对我来说是新手,所以我觉得这可能是一个错误 - $stmt->bind_param('s', $name);
我已与数据库进行比较,所有表名和变量名都是正确的。
的search.php
<html>
<?php
include 'searchform.php';
include 'header.php';
if(isset($_POST['searchsubmit']))
{
$name=$_POST['name'];
if ($stmt = $connection->prepare ("SELECT * FROM users WHERE Username = '$name'"))
{
$stmt->bind_param('s', $name);
$stmt->execute();
$stmt->bind_result($personresult);
$stmt->fetch();
print_r($personresult);
}
else
{
echo "<p>Please enter a search query</p>";
}
}
else
{
echo "NOT SET!";
}
?>
</html>
显示错误
Warning: session_start(): Cannot send session cookie - headers already sent
searchform.php:2 which is displayed underneath:
<br><br><br><br>
<?php
error_reporting(E_ALL);
ini_set('display_errors', -1);
include 'header.php';
include 'connection.php';
?>
<br /><br />
<html>
<header>
<link rel="stylesheet" type="text/css" href="web.css" />
<link rel="stylesheet" type="text/css" href="/web.css" />
</header>
<body>
<center>
<h2>Search for people</h2>
<br />
Please enter the name you wish to search for<br /><br />
<form method="post" action="search.php" id="searchform">
<input type="text" name="name">
<input type="submit" name="searchsubmit" value="Submit">
</form><br /><br/>
Or search people by category
答案 0 :(得分:5)
我认为应该是这样的:
if ($stmt = $connection->prepare ("SELECT * FROM users WHERE Username = ?"))
用一个?作为占位符。
从这里的例子中得到它:http://php.net/manual/en/mysqli-stmt.bind-param.php