php+mysql对下拉框搜索的内容修改

基于上一篇搜索下拉框,内容添加到具体位置后,再对其进行修改。 

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

$con = mysqli_connect("localhost","root","密码","链接的数据库名称");
mysqli_query($con,'set names utf8');
if (!$con){
	echo'链接数据库失败!';
}
?>
<!DOCTYPE html>
<html>
	<head></head>
	<body>
<form action="" method="get" > //action为空就是form表单提交给当前页面
<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(); 
?>


<form action="" method="get" > 

<br /><br /><br /><br /><br /><br />
<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">

<button type="submit" name="" >修改信息</button>

 </form>

<?php

//修改php代码

$id = $_GET["id"];
$user = $_GET['username'];
$pwd = $_GET['password'];
$level = $_GET['level'];
//根据id查到当前要操作的数据

$sql= "update  userinfo set username = '$user', password ='$pwd',level='$level' WHERE id = '$id'";
//执行
 $result=$con->query($sql);

?>
</body>
</html>


猜你喜欢

转载自blog.csdn.net/m0_63172128/article/details/124214048