Tuesday, 28 August 2018
Subscribe to:
Post Comments (Atom)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AutoComplete Test</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script> jQuery(document).ready(function($){
$('#username').autocomplete(
{source:'suggest_username.php',
minLength:2
});
});
</script>
</form>
</head>
<body>
<form action="actest.php" method="POST">
Enter Username:
<input type="text" id="username" />
<br />
<input type="submit" value="Search" />
</body>
</html>
<?php
// here we set the database information
$SERVER = 'localhost';
$USER = 'user';
$PASS = 'password';
$DATABASE = 'database';
// we are instantiating the mysqli database object
$db = new mysqli($SERVER, $USER, $PASS, $DATABASE);
// error check
if($db->connect_errno > 0){
// report an error
die('Unable to connect to database [' . $db->connect_error . ']');
}
$rs = 'SELECT * FROM users WHERE user LIKE "($_REQUEST['term']) .'%'"';
$result = $db->query($rs);
$data = array();
while ($row = $result->fetch_assoc())
{
$data[] = array(
'label' => $row['user'] ,
'value' => $row['user']
);
}
// jQuery wants JSON data
echo json_encode($data);
flush();
$rs = 'SELECT * FROM users WHERE user LIKE "($_REQUEST['term']) .'%'"';
$rs = 'SELECT * FROM users WHERE user LIKE "(' . $_REQUEST['term'] . ')%"';
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment