PHP头条
热点:

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


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

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




查看新闻

 

查看新闻

<?php $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 ""; } ?>
id title author source content date update delete
{$v[0]} {$v[1]} {$v[2]} {$v[3]} {$v[4]} {$v[5]} update delete


发布新闻

  

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




发布新闻

 

 

发布新闻

标题:

作者:

来源:

内容:

  

提交内容后的处理:

<?php
$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="insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";
$result=$db->query($sql);
if($result)
{
  header ("location:xinwen.php");
  }
else
{
  echo "添加新闻失败!";
  }

三、删除内容处理

<?php
$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");
  }
else
{
  echo "删除数据失败";
  }
?>
  

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




修改新闻


 

修改新闻

<?php $newsid = $_GET["newsid"]; $db = new MySQLi("localhost","root","","mydb"); $sinfo = "select * from news where newsid='{$newsid}'"; $r = $db->query($sinfo); $arr = $r->fetch_row(); //这个人的所有信息 ?>

标题:

作者:

来源:

内容:

  

  

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

<?php
$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");
  }
else
{
  echo "修改数据失败!";
  }

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

www.phpzy.comtrue/php/32973.htmlTechArticlephp数据访问之增删改查操作 增删改查操作小练习,大家练练手吧 一、查看新闻页面-----主页面 查看新闻 查看新闻 id title author source content date update delete query($sql);$arr=$result->fetch_all();f...

相关文章

PHP之友评论

今天推荐