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>

实现图样式:

 

猜你喜欢

转载自blog.csdn.net/m0_63172128/article/details/124213882
今日推荐