We have seen the display page, modified, and linked to the modifu.php page
Let’s look at the code of the following page:
<?php require_once('conn.php'); $id = $_GET['id']; $sql = "SELECT * FROM user where id='$id'"; $info = mysql_query($sql); $row = mysql_fetch_array($info); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>修改管理员</title> <style type="text/css"> .ipt{width:180px;height:30px;border-radius:5px;outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;} .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;} </style> </head> <body> <form method="post" action="modifyuser.php?id=<?php echo $id;?>"> 用户名:<input type="username" name="username" class="ipt" value="<?php echo $row['username'];?>"> </br></br> 密 码:<input type="password" name="password" class="ipt" value="<?php echo $row['password'];?>"> </br></br> <input type="submit" value="修改" class="sub"> </form> </body> </html>
Connect to the database
Then Get the id mentioned over there and query based on the id, save the database information to the page, so that we can delete the information and make modifications
Processing the modified php file modifyuser.php We also have a Parameter id
Let’s look at the code of the following modifyuser.php page:
<?php //修改页面php代码 require_once('conn.php'); $name = $_POST['username']; $password = md5($_POST['password']); $id = $_GET['id']; $sql = "UPDATE user SET username='$name',password='$password' where id='$id'"; $res = mysql_query($sql); if($res){ echo "<script>alert('修改管理员成功');location.href='user.php'</script>"; }else{ echo "<script>alert('修改管理员失败');history.go(-1);</script>"; } ?>
With the above code, we have completed the function of modifying the administrator
Next Section