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

增删改查操作小练习,大家练练手吧

一、查看新闻页面-----主页面

rush:xhtml;"> 查看新闻

查看新闻

query($sql); $arr=$result->fetch_all(); foreach ($arr as $v) { echo "updatedelete</tr>";
}

?>
</table>




<div class="xw"><a href="xinwen.php">发布新闻

二、发布新闻页面-----添加内容

发布新闻

发布新闻

<form action="AddChu.php" method="post">
<div class="xw">标题:<input type="text" name="title" style="width:400px">


<div class="xw">作者:<input type="text" name="author">
<div class="xw">来源:<input type="text" name="source">
<div class="xw">内容:
<textarea rows="10" cols="80" name="content">

<div class="a"><input type="submit" value="提交" style="margin-left:600px;">
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;">

提交内容后的处理:

rush:PHP;"> $db=new MySQLi("localhost","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");
}
else
{
echo "添加新闻失败!";
}

三、删除内容处理

rush:PHP;"> query($sql); if($result) { header ("location:ChaKan.PHP"); } else { echo "删除数据失败"; } ?>   

四、修改新闻页面----修改新闻内容后提交查看

rush:xhtml;"> <a href="https://www.jb51.cc/tag/xiugai/" target="_blank" class="keywords">修改</a>新闻

修改新闻

query($sinfo); $arr = $r->fetch_row(); //这个人的所有信息 ?>

<form action="UpdateChu.PHP" method="post">
<div class="xw"><input type="hidden" name="newsid" value="<?php echo $arr[0] ?>">


<div class="xw">标题:<input type="text" name="title" style="width:400px" value="<?php echo $arr[1] ?>">
<div class="xw">作者:<input type="text" name="author" value="<?php echo $arr[2] ?>">
<div class="xw">来源:<input type="text" name="source" value="<?php echo $arr[3] ?>">
<div class="xw">内容:
<textarea rows="10" cols="80" name="content"><?php echo $arr[4] ?>

<div class="a"><input type="submit" value="修改" style="margin-left:600px;">
<div class="a"><a href="ChaKan.PHP"><input type="button" value="查看" style="margin-left:6px;">

  

提交修改内容后进行处理:

rush:PHP;"> $db=new MySQLi("localhost","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");
}
else
{
echo "修改数据失败!";
}

以上就是本文的全部内容,希望对大家学习PHP程序设计有所帮助。

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...