php mysql增删改除页面之编辑页面

    xiaoxiao2021-04-15  206

    编辑页面

    <?php //判断是否接受到id if(empty($_GET['id'])){ exit('没有接收到数据'); } $id=$_GET['id']; $conn =mysqli_connect('localhost','root','123456','yitu'); if (!$conn) { exit('<h1>连接数据库失败</h1>'); } $query = mysqli_query($conn, "select * from users where id={$id};"); if (!$query) { exit('<h1>查询数据失败</h1>'); } //查询到数据后,将数据的关联数组导出来 $user=mysqli_fetch_array($query); function edit(){ //$user,id为全局变量 global $user; global $id; //判断是否为空 if(empty($_POST['name'])){ $GLOBALS['error_message']='请输入姓名'; return; } if(empty($_POST['number'])){ $GLOBALS['error_message']='请输入手机号'; return; } if(!(isset($_POST['vip'])&&$_POST['vip']!=='-1')){ $GLOBALS['error_message']='请选择是否为会员'; return; } $user['name']=$_POST['name']; $user['number']=$_POST['number']; $user['vip']=$_POST['vip']; $conn =mysqli_connect('localhost','root','123456','yitu'); if (!$conn) { exit('<h1>连接数据库失败</h1>'); } $query = mysqli_query($conn, "update users set name='{$user['name']}',number='{$user['number']}',vip='{$user['vip']}' where id={$id}"); if (!$query) { exit('<h1>查询数据失败</h1>'); } header('Location:user.php'); } if($_SERVER['REQUEST_METHOD']=='POST'){ edit(); } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="Untitled-2.css"> <title>后台管理</title> </head> <body> <div class="container"> <!--导航栏--> <!--引入多次用到的模板文件--> <?php include'template.php'?> <!-- 用户管理导航栏--> <div class="main-order"> <?php if(isset($error_message)):?> <div class="alert alert-warning"> <?php echo $error_message;?> </div> <?php endif?> <!--action中要回到自己的id中,否则取不到网页的id值--> <form action="<?php echo $_SERVER['PHP_SELF'];?>?id=<?php echo $user['id'];?>" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="name">用户名</label> <input type="text" id="name" name="name" class="form-control" value="<?php echo $user['name']?>"> </div> <div class="form-group"> <label for="number">手机号</label> <input type="text" id="number" name="number" class="form-control" value="<?php echo $user['number']?>"> </div> <div class="form-group"> <label for="vip">所属用户组</label> <select id="vip" name="vip" class="form-control"> <option value='-1'>限制会员</option> <option value='0'value="<?php echo $user['vip']=='0'?'select':""?>">新手上路</option> <option value='1'value="<?php echo $user['vip']=='1'?'select':""?>">易途会员</option> </select> </div> <div class="modal-footer"> <a href="user.php" class="btn btn-default" data-dismiss="modal">关闭</a> <button class="btn btn-primary">修改</button> </div> </form> </div> </body> <script src="lib/jquery/jquery.min.js"></script> <script src="lib/bootstrap/js/bootstrap.min.js"></script> </html>

    编辑用户张三


    最新回复(0)