码迷,mamicode.com
首页 > Web开发 > 详细

第六十一天上课 PHP新闻内测

时间:2016-05-05 16:01:55      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

发布界面(index.php)

<form action="insert.php" method="post">
<div style="position:absolute; width:500px; font-size:18px; font-weight:bold; top:30px; left:350px">
<div align="center"><font size="+3">发布新闻</font><div><br />
<div align="left">标题:&nbsp;&nbsp;
     <input type="text" name="title"  style="width:300px; font-size:14px;" />
</div><br />
<div align="left">作者:&nbsp;&nbsp;
     <input type="text" name="author" style="width:150px; font-size:14px;" />
</div><br />
<div align="left">来源:&nbsp;&nbsp;
     <input type="text" name="source" style="width:250px; font-size:14px;" />
</div><br />
<div align="left"><table width="600" border="0">
  <tr>
    <td width="70px">内容:</td>
    <td><textarea name="content" rows="10" style="width:400px; font-size:14px; line-height:1.5;"></textarea></td>
  </tr>
</table>
<br />
<div align="center">
    <input style="width:60px; height:30px; font-size:20px;" type="submit" value="发布" />&nbsp;&nbsp;&nbsp;&nbsp;
    <input style="width:60px; height:30px; font-size:20px;"type="button" value="查看" onclick="location.href=‘main.php‘" />
</div>
</div>
</form>

新闻界面(main.php)

<?php
$db=new MySQLi("localhost","root","","index");
!mysqli_connect_error() or die("连接失败");
$sql="select * from new";
$r=$db->query($sql);
$a=$r->fetch_all();
if($r)
{
    echo"<br><br>";
    echo "<table border=‘1px‘ bordercolor=‘#33FF66‘ width=‘1000px‘ align=‘center‘>";
    echo<tr>
            <td align="center">发布序号</td>
            <td align="center">新闻标题</td>
            <td align="center">新闻作者</td>
            <td align="center">新闻来源</td>
            <td align="center">发布时间</td>
            <td align="center">*</td>
            <td align="center">*</td>
            <td align="center">*</td>
         </tr>;
    foreach($a as $i)
    {
        echo"<tr>
                <td align=‘center‘>$i[0]</td>
                <td align=‘center‘>$i[1]</td>
                <td align=‘center‘>$i[2]</td>
                <td align=‘center‘>$i[3]</td>
                <td align=‘center‘>$i[5]</td>
                <td align=‘center‘><a href=‘new.php?code=$i[0]‘>详情</a></td>
                <td align=‘center‘><a href=‘update.php?code=$i[0]‘>修改</a></td>
                <td align=‘center‘><a href=‘delete.php?code=$i[0]‘>删除</a></td>
             </tr>";
    }
}
else
{
    echo "获取失败";
}
?>

新闻详情(new.php)

<?php
$i=$_GET[‘code‘];
$db=new MySQLi("localhost","root","","index");
!mysqli_connect_error() or die("连接失败");
$sql="select * from new where code=‘$i‘";
$r=$db->query($sql);
$a=$r->fetch_row();
?>
<div style="position:absolute; width:500px; font-size:18px; font-weight:bold; top:30px; left:350px">
    <div align="center"><font size="+3">新闻详情</font><div><br />
    <div align="left">标题:&nbsp;&nbsp;
         <input disabled="disabled" type="text" name="title"  style="width:300px; font-size:14px; border:0px; background-color:#FFF; font-weight:bold;" value="<?php echo $a[1]?>" />
    </div><br />
    <div align="left">作者:&nbsp;&nbsp;
         <input disabled="disabled" type="text" name="author" style="width:150px; font-size:14px; border:0px; background-color:#FFF; font-weight:bold;" value="<?php echo $a[2]?>" />
    </div><br />
    <div align="left">来源:&nbsp;&nbsp;
         <input disabled="disabled" type="text" name="source" style="width:250px; font-size:14px; border:0px; background-color:#FFF; font-weight:bold;" value="<?php echo $a[3]?>" />
    </div><br />
    <div align="left">时间:&nbsp;&nbsp; 
         <?php echo $a[5] ?>
    </div><br />
    <div align="left"><table width="600" border="0">
      <tr>
        <td width="70px">内容:</td>
        <td><div style="width:400px; line-height:1.5;"><?php echo $a[4] ?><div></td>
      </tr>
    </table>
    </div>
</div>

修改界面(update.php)

<?php
$i=$_GET[‘code‘];
$db=new MySQLi("localhost","root","","index");
!mysqli_connect_error() or die("连接失败");
$sql="select * from new where code=‘$i‘";
$r=$db->query($sql);
$a=$r->fetch_row();
?>
<form action="xupdate.php" method="post">
<div><input name="code" style="visibility:hidden;" value="<?php echo $a[0] ?>" /></div>
<div style="position:absolute; width:500px; font-size:18px; font-weight:bold; top:30px; left:350px">
<div align="center"><font size="+3">修改新闻</font><div><br />
<div align="left">标题:&nbsp;&nbsp;
     <input type="text" name="title"  style="width:300px; font-size:14px;" value="<?php echo $a[1]?>" />
</div><br />
<div align="left">作者:&nbsp;&nbsp;
     <input type="text" name="author" style="width:150px; font-size:14px;" value="<?php echo $a[2]?>" />
</div><br />
<div align="left">来源:&nbsp;&nbsp;
     <input type="text" name="source" style="width:250px; font-size:14px;" value="<?php echo $a[3]?>" />
</div><br />
<div align="left"><table width="600" border="0">
  <tr>
    <td width="70px">内容:</td>
    <td><textarea name="content" rows="10" style="width:400px; font-size:14px; line-height:1.5;"><?php echo $a[4] ?></textarea></td>
  </tr>
</table>
<br />
<div align="center">
    <input style="position:absolute; right:60px; width:60px; height:30px; font-size:20px;" type="submit" value="修改" />
</div>
</div>
</form>

发布后台(insert.php)

<?php
$a=$_POST[‘title‘];
$b=$_POST[‘author‘];
$c=$_POST[‘source‘];
$d=$_POST[‘content‘];
$e=date("Y-m-d H:i:s",time());
$db=new MySQLi("localhost","root","","index");
!mysqli_connect_error() or die("连接失败");
$sql="insert into new values(‘‘,‘$a‘,‘$b‘,‘$c‘,‘$d‘,‘$e‘)";
$r=$db->query($sql);
if($r)
{
    header(‘location:main.php‘);
}
else
{
    echo "发布失败";
}
?>

 

修改后台(xupdate.php)

<?php
$i=$_POST[‘code‘];
$a=$_POST[‘title‘];
$b=$_POST[‘author‘];
$c=$_POST[‘source‘];
$d=$_POST[‘content‘];
$e=date("Y-m-d H:i:s",time());
$db=new MySQLi("localhost","root","","index");
!mysqli_connect_error() or die("连接失败");
$s="update new set title=‘$a‘,author=‘$b‘,source=‘$c‘,content=‘$d‘,time=‘$e‘ where code=‘$i‘";
$r=$db->query($s);
if($r)
{
    header(‘location:main.php‘);
}
else 
    echo "false";
?>

 

删除后台(delete.php)

<?php
$i=$_GET[‘code‘];
var_dump($i);
$db=new MySQLi("localhost","root","","index");
!mysqli_connect_error() or die("连接失败");
$sql="delete from new where code=‘$i‘";
$r=$db->query($sql);
if($r)
{
    header(‘location:main.php‘);
}
else
    echo "false";
?>

 技术分享

技术分享

技术分享

技术分享

第六十一天上课 PHP新闻内测

标签:

原文地址:http://www.cnblogs.com/lovling/p/5462134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!