首页 > 编程 > PHP > 正文

php数据访问之增删改查操作

2020-03-22 18:08:59
字体:
来源:转载
供稿:网友
meta http-equiv="Content-Type" content="text/html; charset=utf-8" / title 查看新闻 /title /head body h1 查看新闻 /h1 table width="100%" border="1" cellpadding="0" cellspacing="0" td id /td td title /td td author /td td source /td td content /td td date /td td update /td td delete /td /tr $db=new MySQLi("localhost","root","","mydb");!mysqli_connect_error() or die("连接失败!");$sql="select * from news";$result=$db- query($sql);$arr=$result- fetch_all();foreach ($arr as $v) echo " tr td {$v[0]} /td td {$v[1]} /td td {$v[2]} /td td {$v[3]} /td td {$v[4]} /td td {$v[5]} /td td a href='Update.php newsid={$v[0]}' update /a /td td a href='Delete.php newsid={$v[0]}' delete /a /td /tr
meta http-equiv="Content-Type" content="text/html; charset=utf-8" / title 发布新闻 /title style margin-top:10px; margin-left:400px; border:thick; float:left; /style /head body h1 center 发布新闻 /center /h1 form action="AddChu.php" method="post" div 标题: input type="text" name="title" /div div 作者: input type="text" name="author" /div div 来源: input type="text" name="source" /div div 内容: textarea rows="10" cols="80" name="content" /textarea /div div input type="submit" value="提交" /div div a href="ChaKan.php" input type="button" value="查看" /a /div /form
$db=new MySQLi("localhost","root","","mydb");!mysqli_connect_error() or die("联系失败!");$sql="insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";$result=$db- query($sql);if($result) header ("location:xinwen.php"); echo "添加新闻失败!";三、删除内容处理$newsid=$_GET["newsid"];$db=new MySQLi("localhost","root","","mydb");!mysqli_connect_error() or die("连接失败!");$sql="delete from news where newsid='{$newsid}'";$result=$db- query($sql);if($result) header ("location:ChaKan.php"); echo "删除数据失败";四、修改新闻页面----修改新闻内容后提交查看
html head meta http-equiv="Content-Type" content="text/html; charset=utf-8" / title 修改新闻 /title style margin-top:10px; margin-left:400px; border:thick; float:left; /style /head body h1 center 修改新闻 /center /h1 $newsid = $_GET["newsid"];$db = new MySQLi("localhost","root","","mydb");$sinfo = "select * from news where newsid='{$newsid}'";$r = $db- query($sinfo);$arr = $r- fetch_row(); //这个人的所有信息
form action="UpdateChu.php" method="post" div input type="hidden" name="newsid" value=" php echo $arr[0] " /div div 标题: input type="text" name="title" value=" php echo $arr[1] " /div div 作者: input type="text" name="author" value=" php echo $arr[2] " /div div 来源: input type="text" name="source" value=" php echo $arr[3] " /div div 内容: textarea rows="10" cols="80" name="content" php echo $arr[4] /textarea /div div input type="submit" value="修改" /div div a href="ChaKan.php" input type="button" value="查看" /a /div /form /body /html 提交修改内容后进行处理:
$newsid=$_POST["newsid"];$title=$_POST["title"];$author=$_POST["author"];$source=$_POST["source"];$content=$_POST["content"];$time=date("Y-m-d",time());$db=new MySQLi("localhost","root","","mydb");!mysqli_connect_error() or die("联系失败!");$sql="update news set title='{$title}',author='{$author}',source='{$source}',content='{$content}',time='{$time}' where newsid='{$newsid}'";$result=$db- query($sql);if($result) header ("location:Update.php"); echo "修改数据失败!";以上就是本文的全部内容,希望对大家学习php程序设计有所帮助。PHP教程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表