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

新闻发布页面代码

<!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]}' οnclick=\"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 "删除失败";
}

  

转载于:https://www.cnblogs.com/forqiwen/p/8892096.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值