So my problem is simple. I'm a PHP beginner (noob programmer in general, started 3 months ago) and I've been following some tutorials on how to build a "search suggestion" system, that checks in the database if what you're typing is like anything in it and displays the results real time with AJAX.
It is working partially. When I type in a full username, for example, it displays the result. But not when I type half of it, or the first letter.
<?php
require 'connect.php';
if (isset($_GET['searchText'])) {
$searchText = $_GET['searchText'];
}
if($query = $db->prepare("SELECT user_name FROM users WHERE user_name LIKE ?")) {
$query->bind_param('s', $searchText);
$query->execute();
$query->bind_result($searchTextResult);
while ($query->fetch()) {
echo $searchTextResult;
}
}
?>
Also, since I'm a total noob I'd love to have any suggestions on the code just to know if I'm employing good practice in general. I heard binding and mysqli are recommended, so I'm trying to stick to them and I rarely get any criticism at all.