php与mysql已经连接好,怎样在php页面中添加一个“查询”按钮,然后输入要查询的编号,输入mysql中的相关

php与mysql已经连接好,怎样在php页面中添加一个“查询”按钮,点“查询”后,输入要查询的物品编号,输出mysql中已录入的相关的物品信息?
数据库名:mydb
表名:emp
没有分了,各位大神帮忙,感激不尽!

说一下简单的查询:

<form>

请输入产品名:<input type="text" name="key">

                 <input type="submit" name="submit" value="查询">

</form>

效果图:

然后加入以下php代码:

<?php

 $conn=mysql_connect("localhost","用户名","密码");

mysql_select_db("mydb",$conn);

mysql_query("SET NAMES gbk");

  if($_POST['submit']!="")

{

 $key=$_POST['key'];

 $sql="select * from emp where name like '$key'";   //此处以name这个数据库中的字段为例

$rs=mysql_query($sql,$conn);

while($info=mysql_fetch_array($rs)){

  echo $info['name'];    //输出产品相关信息

}

}

?>

如果是高级查询的话,需要几个条件,在查询语句里加个and和查询条件就可以了

参考资料:http://blog.sina.com.cn/zuiwomengxi

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-18
表单页
<form action="search.php" method="post">
<input type="text" name="code">
<imput type="submit" value="查询">
</form>

处理页search.php
<?php
//连接数据库后
$code=$_POST[code];
$mysql=mysql_query("select*from emp where code='$code'");
$row=mysql_fetch_array($mysql);
do{
echo"<tr><td>".$row[code]."</td><td>".$row[type]."</td></tr>";
}while($row=mysql_fetch_array($mysql));
//记得要关闭连接,自己弄吧
?>
第2个回答  2010-12-19
页面1
<form name=form1 method=post action=check.php>
请输入物品编号:<input type=text name=num>
<input type=submit value=查询>

页面2(check.php)
<?php
...//连接服务器
if(isset($_POST[num]) && $_POST[num]!=""){//先判断此页有没有传入参数.有则处理无则不处理
$num=$_POST[num];
$sql="select * from table where num='$num'";//用*不好..最好用哪些字段写哪些
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){
echo "名称是:".$result[name];//物品名称字段
echo "价格是:".$result[price];//物品价格字段
...
}
?>
相似回答