Here is the original syntax:
<?php
$db = new mysqli('DB_HOST', 'USERNAME' ,'PASSWORD', 'DATABASE_NAME');
if(!$db) {
echo 'Could not connect to the database.';
} else {
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT country FROM countries WHERE country LIKE '$queryString%' LIMIT 10");
if($query) {
echo '<ul>';
while ($result = $query ->fetch_object()) {
echo '<li onClick="fill(\''.addslashes($result->country).'\');">'.$result->country.'</li>';
}
echo '</ul>';
} else {
echo 'OOPS we had a problem :(';
}
} else {
// do nothing
}
} else {
echo 'There should be no direct access to this script!';
}
}
?>
and I edit it:
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_password = '';
$db_name = 'db_upload';
$db = mysql_connect($db_host , $db_user ,$db_password, $db_name);
if(isset($_POST['queryString'])) {
$queryString = mysql_real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = mysql_query("SELECT country FROM countries WHERE country LIKE '$queryString%' LIMIT 10");
if($query) {
echo '<ul>';
while ($result = mysql_fetch_object($query)) {
echo '<li onClick="fill(\''.addslashes($result->country).'\');">'.$result->country.'</li>';
}
echo '</ul>';
} else {
echo 'OOPS we had a problem :(';
}
} else {
// do nothing
}
} else {
echo 'There should be no direct access to this script!';
}
?>
when i run it, it was always fall in else statement
'OOPS we had a problem :('
even I input correct data.
here is the link where I found the code:
jQuery PHP Ajax Autosuggest | Ashley Ford - Tutorials :: jQuery :: PHP :: CSS :: HTML5 :: Papermashup.com
Thank you


Sign In
Create Account


Back to top









