php 增删改查---增

<meta charset="utf-8">
<?php

//连接数据库
$db = new MySQLi('localhost','root','','php');
!mysqli_connect_error() or die('连接失败');
$db->query('set names utf8');

//判断

if(!empty($_GET['id'])){
$sql="delete from student where sno=".$_GET['id'];
$res=$res->query($sql);
}

//查找库里的内容
$sql='select * from student';
$res=$db->query($sql);
$arr=$res->fetch_all();
?>

//这个事添加按钮

<a href="ye_3.php">添加</a>

//这是个表
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>生日</th>
<th>班级</th>
<th>操作</th>
</tr>

//把库中的内容添加到表中
<?php foreach($arr as $i){?>
<tr>
<td><?php echo $i[0]; ?></td>
<td><?php echo $i[1]; ?></td>
<td><?php echo $i[2]; ?></td>
<td><?php echo $i[3]; ?></td>
<td><?php echo $i[4]; ?></td>
<td>

//删除以及修改按钮
<a href="ye_1.php">删除</a>
<a href="ye_2.php">修改</a>
</td>
</tr>
<?php }?>
</table>
</body>
</html>

 

 

在页面2中进行一下操作

<meta charset="utf-8">

//首先连接数据库
<?php
$db = new MySQLi('localhost','root','','php');
!mysqli_connect_error() or die('连接失败');
$db->query('set names utf8');

//定义常量

$sno = $_POST['sno'];
$sname = $_POST['sname'];
$ssex = $_POST['ssex'];
$sbirthday = $_POST['sbirthday'];
$clsaa = $_POST['clsaa'];

$sql = "insert into student values('$sno','$sname','$ssex','$sbirthday','$clsaa')";

$res = $db->query($sql);

//进行判断,添加内容
if($res){
header('location:ye_1.php');
}else{
header('location:ye_2.php');
}

?>

 

第三个页面写需要填写表的内容

//from表单进行添加内容,传值到页面2

<form action="ye_2.php" method="post">
编号:<input type="text" name="sno"><br>
姓名:<input type="text" name="sname"><br>
性别:<input type="text" name="ssex"><br>
生日:<input type="text" name="sbirthday"><br>
班级:<input type="text" name="clsaa"><br>
<button>提交</button>
</form>

转载于:https://www.cnblogs.com/sword082419/p/9011789.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值