php技术第二天!
继续搞登录成功之后跳转的页面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>学生列表</title>
</head>
<body>
<h3>学生列表</h3>
<a href="add.php">添加</a>
<table width="360" border="1" cellpadding="0">
<tr>
<th>学号</th>
<th>名字</th>
<th>密码</th>
<th>成绩</th>
<th>操作</th>
</tr>
<?php
//去数据库查询数据
include "db.php";
$sql="select * from user ";
$rs= mysqli_query($conn, $sql);
foreach($rs as $row){
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['name']}</td>";
echo "<td>{$row['pwd']}</td>";
echo "<td>{$row['score']}</td>";
echo "<td><a href='update.php?id={$row['id']}'>修改</a><a href='delete.php?id={$row['id']}'>删除</a>";
echo "</tr>";
}
?>
</table>
</body>
</html>
用select 和foreach把查询到的数据循环输出
添加删除需改三个超链接并提供id并跳转到相应的页面 括弧添加不需要提供id
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改</title>
</head>
<body>
修改
<form action="updateServer.php" method="get">
<?php
//获取上一个页面传递过来的id,
$id=$_GET["id"];
include "db.php";
//根据id去数据库中拿出当前学生的信息
$sql="select * from user where id=$id";
$rs=mysqli_query($conn, $sql);
$name=null;
$pwd=null;
$score=null;
foreach($rs as $row){
$name=$row['name'];
$pwd=$row['pwd'];
$score=$row['score'];
}
echo "学号:<input type='text' value='$id' readonly name='id'/><br>";
echo "名字:<input type='text' value='$name' name='name'/><br>";
echo "密码:<input type='text' value='$pwd' name='pwd'/><br>";
echo "成绩:<input type='text' value='$score' name='score'/><br>";
?>
<input type="submit" value="更新" /><br>
</form>
</body>
</html>
修改的页面
获取到上个页面传过来的id然后也可以select显示出来当前id的各项数据建议id设为只读
然后点击修改进入修改功能页面
<?php
include("db.php");
//获取前端参数
$id=$_GET['id'];
$name=$_GET['name'];
$pwd =$_GET['pwd'];
$score=$_GET['score'];
//更新到数据库
$sql="update user set name = '$name',pwd = '$pwd',score=$score where id = $id";
$rw= mysqli_query($conn,$sql);
if($rw){
echo "<script>alert('更新成功');location.href='list.php'</script>";
}else{
echo "更新失败');location.href='update.php?id=$id'</script>";
}
?>
获取前端各项参数,然后update更新到数据库 一个判断 成功就跳转到表页面,失败就在修改界面并且返回id
感觉自己写了好多,今天就写这些吧。感谢观看,也希望能得到大佬的指点:)