例子 新闻发布

1.新闻发布主页面

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 <style>
 7 *{ margin:0px auto; padding:0px}
 8 </style>
 9 </head>
10 
11 <body>
12 
13 <form action="newstijiao.php" method="post">
14     <div style="width:500px; height:400px; position:relative">
15         <div style="font-size:16px; text-align:center; padding-top:20px">发布新闻</div>
16         <div style="margin-top:20px">标题:<input name="title" type="text" style="width:240px; height:20px; margin-left:10px" /></div>
17         <div style="margin-top:10px">作者:<input name="author" type="text" style="width:150px; height:20px; margin-left:10px" /></div>
18         <div style="margin-top:10px">来源:<input name="source" type="text" style="width:150px; height:20px; margin-left:10px" /></div>
19         <div style="margin-top:10px">内容:<input name="content" type="textarea" style="width:420px; height:120px; margin-left:10px" /></div>
20 
21     <div style="float:left; margin-left:200px"><input type="submit" value="提交" style="width:50px; height:30px; margin-top:10px" /></div>
22 
23 <form action="newsmain.php">
24     <div style="float:left"><input type="submit" value="查看" style="margin-top:10px; width:50px; height:30px; margin-left:10px" /></div>
25 </form>
26 </div>
27 </form>
28 </body>
29 </html>

2.新闻提交的处理界面

<?php 
$newsid = "";
$title = $_POST["title"];
$author = $_POST["author"];
$source = $_POST["source"];
$content = $_POST["content"];
$time = date('y-m-d h:i:s',time());
echo $title;
//造连接对象
$db = new MySQLi("localhost","root","666","newssystem");

$sql = "insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";
$db->query($sql);
header("location:newsmain.php");

3.页面提交至新闻列表界面

<!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>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>newsid</td>
        <td>title</td>
        <td>Author</td>
        <td>source</td>
        <td>content</td>
        <td>time</td>
        <td>update</td>
        <td>delete</td>
    </tr>

<?php 
    $db = new MySQLi("localhost","root","666","newssystem");
    $sql = "select * from news";
    $result = $db->query($sql);
    $attr = $result->fetch_all();
    foreach($attr as $v)
    {
        echo "<tr>";
        
        echo"<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='newsupdate.php?c={$v[0]}')\">update</a></td><td><a href='newsdelete.php?c={$v[0]}' onclick=\"return confirm('确定删除吗?')\">delete</a></td>";
    }
    
    ?> 

</table>
</body>
</html>

4.删除处理界面

<?php 
$newsid = $_GET["c"];
$db = new MySQLi("localhost","root","666","newssystem");
$sql = "delete from news where newsid='{$newsid}'";
$r = $db->query($sql);

if($r)
{
    header("location:newsmain.php");
}
else
{
    echo "删除失败";
}

5.提交处理界面

<?php
$newsid = $_POST["newsid"];
$title = $_POST["title"];
$author = $_POST["author"];
$source = $_POST["source"];
$content = $_POST["content"];
$time = date('y-m-d h:i:s',time());

$db = new MySQLi("localhost","root","666","newssystem");

$sql = "update news set title='{$title}',author='{$author}',source='${source}',content='${content}',time='{$time}' where newsid='{$newsid}'";
$db->query($sql);
header("location:newsmain.php");

6.修改处理界面

<!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>
<style>
*{ margin:0px auto; padding:0px}
</style>
</head>

<body>

<?php 
$newsid = $_GET["c"];
$db = new MySQLi("localhost","root","666","newssystem");
$sql = "select * from news where newsid='{$newsid}'";

$result = $db->query($sql);

$attr = $result->fetch_all();
foreach($attr as $a)
{
    
}


 
?>

<form action="newstijiaochuli.php" method="post">
    <div style="width:500px; height:400px; position:relative">
        <div style="font-size:16px; text-align:center; padding-top:20px">发布新闻</div>
        <div style="margin-top:20px"><input value="<?php echo $a[0] ?>" name="newsid" type="hidden" /></div>
        <div style="margin-top:20px">标题:<input value="<?php echo $a[1] ?>" name="title" type="text" style="width:240px; height:20px; margin-left:10px" /></div>
        <div style="margin-top:10px">作者:<input value="<?php echo $a[2] ?>" name="author" type="text" style="width:150px; height:20px; margin-left:10px" /></div>
        <div style="margin-top:10px">来源:<input value="<?php echo $a[3] ?>" name="source" type="text" style="width:150px; height:20px; margin-left:10px" /></div>
        <div style="margin-top:10px">内容:<input value="<?php echo $a[4] ?>" name="content" type="textarea" style="width:420px; height:120px; margin-left:10px" /></div>

    <div style="float:left; margin-left:200px"><input type="submit" value="修改" style="width:50px; height:30px; margin-top:10px" /></div>

<form action="newsmain.php">
    <div style="float:left"><input type="submit" value="查看" style="margin-top:10px; width:50px; height:30px; margin-left:10px" /></div>
</form>
</div>
</form>
</body>
</html>

 

转载于:https://www.cnblogs.com/chenshanhe/p/6861057.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值