Figure : img1.通过”添加信息“,进入表单页面:data.php
Figure : img2.进入是adddata.html
Figure : img3.接收表单数据并处理页面:insert.php<?php
//1.接收表单数据
$name = $_POST[‘username’];
$age = $_POST[‘age’];
$sex = $_POST[‘sex’];
$address = $_POST[‘address’];
$tel = $_POST[‘tel’];
//2.判断是否为空
if($name == ‘’ || $age == ‘’ || $sex == ‘’ || $address == ‘’ || $tel == ‘’){
echo ‘数据不能为空!’;
exit;
}
//3.链接数据库
$link = @mysql_connect(‘127.0.0.1’,’root’,’’);
//4.选择数据库
mysql_select_db(‘php07’);
//5.设置编码
mysql_query(‘set names utf8’);
//6.准备SQL语句
$sql = “insert into php07_student values(null,’{$name}’,{$age},’{$sex}’,’{$address}’,’{$tel}’)”;
//7.发送SQL语句
$res = mysql_query($sql);
//8.判断结果
if($res){
echo ‘添加信息成功’;
}else{
echo ‘添加信息失败’;
}
?>1.在显示数据的页面获取数据并显示到相应的位置:data.php
Figure : img
Figure : img说明:分页是根据limit获取的数据数量显示到页面中的一种方式。需要:页码每页显示的数量偏移量:(当前页码-1)*每页显示数量Limit 偏移量,数量最大页码:ceil(总数/每页显示的数量);1.把超链接设置成分页的码数–页码
Figure : img2.通过超链接的页码进行操作数据库
Figure : img
Figure : img1.通过删除超链接传递一个要删除的数据id值到操作页面:data.php
Figure : img2.接收id值并操作删除的页面:delete.php
Figure : img1.通过修改的超连接传递id到修改的表单页面:data.php
Figure : img2.接收id并对应的数据显示表单中–修改表单页面:update.php
Figure : img
Figure : img4.接收表单信息并处理页面:update-date.php<?php
//1.接收表单的数据
$name = $_POST[‘name’];
$age = $_POST[‘age’];
$sex = $_POST[‘sex’];
$address = $_POST[‘address’];
$tel = $_POST[‘tel’];
$id = $_POST[‘id’];
//2.链接数据库
$link = @mysql_connect(‘127.0.0.1’,’root’,’’);
//3.选择数据库
mysql_select_db(‘php07’);
//4.设置编码
mysql_query(‘set names utf8’);
//5.准备SQL语句
$sql = “update php07_student set name=’{$name}’,age={$age},sex=’{$sex}’,address=’{$address}’,tel=’{$tel}’ where id={$id}”;
//6.发送SQL语句
$res = mysql_query($sql);
//7.判断是否成功
if($res){
echo ‘修改成功’;
}else{
echo ‘修改失败’;
}
?><?php
//1.接收表单数据
$name = $_POST[‘username’];
$age = $_POST[‘age’];
$sex = $_POST[‘sex’];
$address = $_POST[‘address’];
$tel = $_POST[‘tel’];
//2.判断是否为空
if($name == ‘’ || $age == ‘’ || $sex == ‘’ || $address == ‘’ || $tel == ‘’){
echo ‘数据不能为空!’;
exit;
}
//3.链接数据库
$link = @mysql_connect(‘127.0.0.1’,’root’,’’);
//4.选择数据库
mysql_select_db(‘php07’);
//5.设置编码
mysql_query(‘set names utf8’);
//6.准备SQL语句
$sql = “insert into php07_student values(null,’{$name}’,{$age},’{$sex}’,’{$address}’,’{$tel}’)”;
//7.发送SQL语句
$res = mysql_query($sql);
//8.判断结果
if($res){
echo ‘添加信息成功’;
}else{
echo ‘添加信息失败’;
}
?>