新闻发布,对内容显示,删除及修改

新闻发布页面代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form action="./fabu.chuli.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 name="content"></textarea></div>
<div><input type="hidden" name="time" value="<?php echo date('Y-m-d H:i:s') ?>" /></div>
<div><input type="submit" value="提交"/><a href="./chakan.php"><input type="button" value="查看" /></a></div>
</form>
</body>
</html>

 ./fabu.chuli.php处理界面,注意下时间的存法//获得当前时间

<div><input type="hidden" name="time" value="<?php echo date('Y-m-d H:i:s') ?>" /></div>
<?php
require_once "./dbda/DBDA.class.php";
$db = new DBDA();
$title = $_POST["title"];
$author = $_POST["author"];
$source = $_POST["source"];
$content = $_POST["content"];
$time = $_POST["time"];
$sql = "insert into news values(0,'{$title}','{$author}','{$source}','{$content}','{$time}')";
$result = $db->query($sql,1);
if($result){
		 echo "<script type='text/javascript'>window.location.href='xinwenfabu.php';</script>";
	}else{
		echo "添加失败";
		}

  点击查看跳转到chakan.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table class="table">
  <caption>基本的表格布局</caption>
  <thead>
    <tr>
      <th>标题</th>
      <th>作者</th>
      <th>来源</th>
      <th>内容</th>
      <th>时间</th>
      <th>修改</th>
      <th>删除</th>
    </tr>
  </thead>
  <tbody>
    <?php
		require_once "./dbda/DBDA.class.php";
		$db = new DBDA();
		$sql = "select * from news";
		$arr = $db->query($sql);
		foreach($arr as $v){
			echo "<tr><td>$v[1]</td>
				  <td>$v[2]</td>
				  <td>$v[3]</td>
				  <td>$v[4]</td>
				  <td>$v[5]</td>
				  <td><a href='./xiugai.php?ids={$v[0]}'>update</a></td>
				  <td><a href='./delete.php?ids={$v[0]}' onclick=\"return confirm('确认删除吗?')\">delete</a></td></tr>
				  ";
		}
	?>
  </tbody>
</table>
</body>
</html>

  <a>标签里的?ids是用get方式传到。delete.php处理页面

 

<?php
$ids = $_GET["ids"];
require_once "./dbda/DBDA.class.php";
$db = new DBDA();
$sql = "delete from news where newsid='{$ids}'";
$result = $db->query($sql,1);
if($result){
echo "删除成功";
}else{
echo "删除失败";
}

  

posted @ 2018-04-22 15:53  FTHeD  阅读(162)  评论(0编辑  收藏  举报