搜索栏错误:对非对象的函数bind_param()

时间:2016-04-17 07:32:04

标签: php mysql

希望得到一些帮助。我的搜索栏出错:在非对象上调用成员函数bind_param()。

我不确定如何解决它,认为可能还有其他一些问题?

<?php

$servername = "localhost";
$name = "root";
$password = "root";
$dbname = "coursework_db";

// Create connection
$conn = new mysqli($servername, $name, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$partialSearch = "%". $_POST['partialSearch'] ."%";
$stmt = $conn->prepare("SELECT username, memberID FROM members WHERE username LIKE ?% 
                    LIMIT 3");

$stmt->bind_param('s',$partialSearch);
$stmt->execute();
$stmt->bind_result($user);
$results = $stmt->fetchAll();

if($results > 0) {
foreach($results as $user) {
echo '<p><a href="ViewProfile.php?uid=' .$user['username']. '"> ' .  $user['memberID'] . ' </a></p>';
}
} else {
print "<p>No Results</p>";
}
?>

我知道用户名和memberID是错误的方式,但ID就像身份用户名一样。

提前感谢您的帮助!

0 个答案:

没有答案