分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

php 增删改查---增

发布时间:2023-09-06 01:53责任编辑:白小东关键词:暂无标签

<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>

php 增删改查---增

原文地址:https://www.cnblogs.com/sword082419/p/9011789.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved