php+MySQL 实现下拉框的搜索

<?php
error_reporting(0);//加上error_reporting(0);就不会弹出警告了
header("Content-type:text/html;charset=utf-8");//防止中文乱码

$con = mysqli_connect("localhost","mysql名","mysql密码","要链接的数据库名");
mysqli_query($con,'set names utf8');

if (!$con){
	echo'链接数据库失败!';
}
?>

<!DOCTYPE html>
<html>
	<head></head>
	
<body>
	
<form action="" method="get" > 
  <select name="id" >
	        <option >请选择</option>
               <?php	
                   $sql="select * from userinfo  ";
					$res=mysqli_query($con,$sql); 
					
				   while($row=$res->fetch_assoc()){					
				     	//var_dump($row);
					?>	
			
					<option> 
					   <?php echo $row["id"];?>
					   <?php echo $row["username"];?> 
							
			</option>
						
                <?php
				 }
				 ?>
 
 </select>
 	
         <input type="submit" value="提交">
 </form>

<?php
$id = $_GET["id"];
//根据id查到当前要操作的数据
$sql= "select * from userinfo where id = '$id'";
//查询
 $result=$con->query($sql);
 // var_dump($result);//dedao
 //得到具体信息
 $res = $result->fetch_assoc(); 
?>


<input type="hidden" value="<?php echo $res['id'];?>  "   name="id" >

<label><b>修改的用户姓名</b></label>
<input type="text" value="<?php echo $res['username'];?>  "   name="username">	
<label><b>用户密码</b></label>
<input type="text" value="<?php echo $res['password'];?>  "  name="password" >	
<label><b>用户级别:</b></label>	
<input type="text" value="<?php echo $res['level'];?>  "   name="level">

</body>
</html>

实现图样式:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彩色面团儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值