Chathurika Chathurika - 4 months ago 12x
SQL Question

MYSQL Error when making Auto complete text box

I want to make a auto complete text box for select employee name from DB. But it makes query error which is

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in

Following is my code.

include 'func/db_connect.php';
if(!empty($_POST["keyword"])) {
$query ="SELECT * FROM employee WHERE name like '" . $_POST["keyword"] . "%' ORDER BY name LIMIT 0,6";


if(!empty($result)) {
<ul id="name-list">
foreach($result as $name) {
<li onClick="selectName('<?php echo $name["name"]; ?>');"><?php echo $name["name"]; ?></li>
<?php } ?>
<?php } } ?>

What is the wrong with this code, can anyone help me !


Try this

while($data = mysql_fetch_assoc($result))
    $row[] = $data;

And change !empty($result) to count($row) > 1