数据库:
前台页面:choseForm.php
function showUser(str){
var xmlhttp;
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
Select a User:
Please Choose
Peter Griffin
Lois Griffin
Glenn Quagmire
Joseph Swanson
后台文件:getuser.php
$q=$_GET["q"];
$mysql_server_name="localhost"; //数据库服务器名称
$mysql_username="root"; // 连接数据库用户名
$mysql_password="cxst789"; // 连接数据库密码
$mysql_database="user"; // 数据库的名字
// 连接到数据库
$con=mysql_connect($mysql_server_name, $mysql_username,
$mysql_password);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db("user", $con);
$sql="SELECT * FROM user WHERE id = ‘".$q."‘";
$result = mysql_query($sql);
echo "
Firstname | Lastname | Age | Hometown | Job |
---|
while($row = mysql_fetch_array($result))
{
echo "
";echo "
" . $row[‘FirstName‘] . "";echo "
" . $row[‘LastName‘] . "";echo "
" . $row[‘Age‘] . "";echo "
" . $row[‘Hometown‘] . "";echo "
" . $row[‘Job‘] . "";echo "
";}
echo "
";mysql_close($con);
?>
原文:http://15129824665.blog.51cto.com/10510385/1771839