0

Hoping for some help. Im getting an error with my search bar: Call to a member function bind_param() on a non-object.

Im not sure how to resolve it, think there may be a few other problems too?

<?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>";
}
?>

Im aware that the username and memberID are the wrong way round, but id like the identification to be their username.

Thanks in advance for any help!

imconnor
  • 405
  • 1
  • 3
  • 10

0 Answers0