php链接数据库 然后再页面上面有 输入ID的文本框 有查询按钮 点击查询按钮 在数据库中查找符合

的数据信息 在页面上显示出来 求完整代码 数据库fenzu 表think_user 里面有 id name time

<form action="" method="get">
请输入ID号:<input type="text" name="word" />
<input type="submit" value="查询" />

</form>

<?php

if(!($_GET["word"])){

exit();//没有数据

}

mysql_connect("127.0.0.1",用户名,密码);

$sql="use fenzu

select * from think_user

where id={$_GET['word']}

";

$rs=mysql_query($sql);

$num=mysql_num_rows($rs);

//获取影响行数,0表示没查到

if(!($num)){

echo '数据不存在!';

}

$row=mysql_fetch_array($rs);//如果有多条数据请用循环

echo "id:{$row['id']}";

echo "名字:{$row['name']}";

echo "时间:{$row['time']}";

//手机打的没测试过,应该没什么问题
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-05-20
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"></head>
<body>
<form action="" method="get">
请输入ID号:<input type="text" name="word" />
<input type="submit" value="查询" />

</form>

<?php

if(!($_GET["word"])){

exit();//没有数据

}

mysql_connect("127.0.0.1","用户名","密码");

mysql_select_db("fenzu");

$sql="use fenzu select * from think_user where id={$_GET['word']} ";

$rs=mysql_query($sql);

$num=mysql_num_rows($rs);

//获取影响行数,0表示没查到

if(!($num)){

echo '数据不存在!';

}
//查询所有符合条件的记录并显示出来。
while($row=mysql_fetch_array($rs))
{

echo "id:{$row['id']}";

echo "名字:{$row['name']}";

echo "时间:{$row['time']}";
echo "<br>";
}
?>
</body>
</html>
//借鉴楼上的。
相似回答