ajax lookup query

Hi all,

I’m trying to have an ajax loaded input box that searches the database for similar results for selection however its not quite there…

this is my html page…
[php]


<script>
$(document).ready(function(){
$('input.typeahead').typeahead({
    name: 'typeahead',
    remote:'/PAGES/includes/scripts/contacts_ajax_code.php?key=%QUERY',
    limit : 10
});

});

<style type="text/css">

.bs-example{
font-family: sans-serif;
position: relative;
margin: 50px;
}
.typeahead, .tt-query, .tt-hint {
border: 2px solid #CCCCCC;
border-radius: 8px;
font-size: 24px;
height: 30px;
line-height: 30px;
outline: medium none;
padding: 8px 12px;
width: 396px;
}
.typeahead {
background-color: #FFFFFF;
}
.typeahead:focus {
border: 2px solid #0097CF;
}
.tt-query {
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
}
.tt-hint {
color: #999999;
}
.tt-dropdown-menu {
background-color: #FFFFFF;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 8px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
margin-top: 12px;
padding: 8px 0;
width: 422px;
}
.tt-suggestion {
font-size: 24px;
line-height: 24px;
padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
background-color: #0097CF;
color: #FFFFFF;
}
.tt-suggestion p {
margin: 0;
}

Ajax Search Box using Node and MySQL

  </div>

[/php]

and this is my PHP query…
[php]<?php

$key=$_GET[‘key’];
$array = array();

include('../mysqli_connect.php');

if (mysqli_connect_errno($db)) {
    trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);

$query = "SELECT * from `fms_tbl_contacts` WHERE `client_id`= '{$_SESSION['client_id_of_user']}' AND  `name` LIKE ".$_GET['key'];
$result = mysqli_query($db, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($db), E_USER_ERROR);

if($result) {
	while($contact = mysqli_fetch_assoc($result)) {

$array[] = $contact['name'];
}
echo json_encode($array);
}

?>[/php]

And when I type a character in the input box I receive the following error;-
jquery.min.js:4 GET PAGES/includes/scripts/contacts_ajax_code.php?key=g 500 (Internal Server Error)

I’ve checked the physical location of the above script and it is there.

Can anyone spot the error of my ways?

I am not familiar with typehead, so I can’t help there.

500 codes are generic catchalls. Check your error log to spot the problem. It could be anything from permissions to a whatever.

Sponsor our Newsletter | Privacy Policy | Terms of Service