时间:2021-07-01 10:21:17 帮助过:4人阅读
数据库教程添加、修改、删除基础操作代码
这是一款比较适合php教程初学者学的教程哦,我们利用一个简单的实例来对数据库添加、修改、删除哦,这样更系统的让各位知道php mysql教程数据库操作的要点。
*/
require_once('common.php');
$action = $_get['action'];
?>
人才列表
if($action=='add'){
?>
}
elseif($action=='save'){
$login = isset($_post['login']) ? $_post['login'] : '';
$pws = isset($_post['pws']) ? $_post['pws'] : '';
$question = isset($_post['question']) ? $_post['question'] : '';
$answer = isset($_post['answer']) ? $_post['answer'] : '';
$sql = "insert into person (login,pws,question,answer)
values('$login','$pws','$question','$answer')";
$db->query($sql);
forward('发布成功','href','personlist.php');
}elseif($action=='del'){
$person_id=$_get['person_id'];
$page=$_get['page'];
$sql="delete from person where person_id='$person_id'";
$db->query($sql);
forward('删除成功','href','personlist.php?page='.$page);
}
elseif($action=='editsave'){
$person_id = isset($_post['person_id']) ? $_post['person_id'] : '';
$page = isset($_post['page']) ? $_post['page'] : '';
$login = isset($_post['login']) ? $_post['login'] : '';
$pws = isset($_post['pws']) ? $_post['pws'] : '';
$question = isset($_post['question']) ? $_post['question'] : '';
$answer = isset($_post['answer']) ? $_post['answer'] : '';
$sql="update person set login='$login',pws='$pws',question='$question',answer='$answer' where person_id='$person_id'";
$db->query($sql);
forward('修改成功','href','personlist.php?page='.$page);
}
elseif($action=='edit'){
$person_id=$_get['person_id'];
$page=$_get['page'];
$sql="select * from person where person_id='$person_id'";
$query = $db->query($sql);
$row = $db->fetch_array($query);
$login=$row['login'];
$pws=$row['pws'];
$question=$row['question'];
$answer=$row['answer'];
?>
}
else{
$page = isset($_get['page']) ?intval($_get['page']) : 1;
$num = 5;
$sql="select * from person";
$query = $db->query($sql);
$totalnum = $db->num_rows($query);//记录总数
$pagenum = ceil($totalnum/$num); //总页数
$offset = ($page-1) * $num;
$sql=$sql." limit $offset,$num ";
$query = $db->query($sql);//取得记录
?>
记录总数:————添加人员
登陆账号
登陆密码
问题
答案
加入时间
操作
while ($row = $db->fetch_array($query)) {
?>
&page=">删除/
&page=">修改
}
?>
}
?>
1 2 3 4
http://www.bkjia.com/PHPjc/630832.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630832.htmlTechArticle数据库添加、修改、删除基础操作代码这是一款比较适合php初学者学的教程哦,我们利用一个简单的实例来对数据库添加、修改、删除哦,...