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

发布界面(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";
?>

时间: 2024-08-29 19:47:48

第六十一天上课 PHP新闻内测的相关文章

QT开发(六十一)———Json简介

QT开发(六十一)---Json简介 一.JSON简介 1.JSON简介 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,基于JavaScript(Standard ECMA-262 3rd Edition - December 1999)的一个子集. JSON采用完全独立于语言的文本格式,使用了类C语言家族的习惯(包括C.C++.C#.Java.JavaScript.Perl.Python等). JSON使用JavaScript语法来描述数据对象,但

第三百六十一节,Python分布式爬虫打造搜索引擎Scrapy精讲—倒排索引

第三百六十一节,Python分布式爬虫打造搜索引擎Scrapy精讲-倒排索引 倒排索引 倒排索引源于实际应用中需要根据属性的值来查找记录.这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址.由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而称为倒排索引(inverted index).带有倒排索引的文件我们称为倒排索引文件,简称倒排文件(inverted file). 倒排索引原理 就是将一句话进行分词并记录分词所存在的文章,当用户搜索词时可以直接查找到当前词所存在的文

“全栈2019”Java第六十一章:如何实现接口?

难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第六十一章:如何实现接口? 下一章 "全栈2019"Java第六十二章:接口与常量详解 学习小组 加入同步学习小组,共同交流与进步. 方式一:关注头条号Gorhaf,私信"Java学习小组". 方式二:关注公众号Gorhaf,回复"Java学习小组".

一个屌丝程序猿的人生(六十一)

听到郑忠科这话,任瑞强的心里忍不住有点窃喜,如果林萧的项目是枪手写的话,那一会儿上台,林萧肯定免不得要出丑了. 不过,任瑞强注定是要失望了. 因为此刻林萧的心里,也在偷着乐呢,他心里想的是,"这可不是我要装逼的,这是老师让我上去的." 这就像上次追女生的例子一样,郑忠科成功的充当了那个第三人,让林萧得以完美装逼. 不过林萧很清楚,越是这种时刻,越要保持低调. 因此,林萧并没有立即上去,而是委婉的拒绝道:"老师,我就不上去耽误大家时间了,还是让其它同学讲吧." 在林萧

第三百六十一天 how can I 坚持

gradle编译,maven编译,不细致的学,搞不了,以为按教程弄一下就会 很顺利的把spring编出来,没想到没那么简单. 脑子浑的厉害,都动不起来了,年龄大了获取就这个样子了,好可怕.好像能体会到父母的感受了,多睡会觉吧. 跑鞋到了,还不赖.. 时间过得真快,下周清明放假了,然后是五一.然后端午,然后又十一... 得抓紧定下来,未来 孩子他妈,你在哪啊...哈哈.. 睡觉..

JAVA学习笔记(六十一)- 反射Reflection

反射Reflection import java.lang.reflect.Modifier; /* * 反射Reflection * java.lang.Class类 */ public class Test01 { public static void main(String[] args) { String name = "tom"; // 方式一:通过对象getClass()方法 // 任意一个类的对象,都有一个getClass()方法 // 可以通过此获取获取当前对象的类型所

面向对象程序设计-C++ Operator Overloading &amp; Type conversion (Static)【第十一次上课笔记】

本次上课继续讲解了 [ ] .-> 等运算符重载的具体例子 也讲解了C++单个参数的类的类型转换的案例 最后稍微提到了 static 的第三种作用:静态数据成员 具体详解我都已注释出来了,大家可以慢慢看 有任何问题都可以在这篇文章下留言我会及时解答 :) #include <iostream> #include <cmath> using namespace std; class myArray { private: float * p; unsigned int size;

第一百六十一节,封装库--JavaScript,完整封装库文件

封装库--JavaScript,完整封装库文件 /** *feng_zhuang_ku_1.0版本,js封装库,2016/12/29日:林贵秀 **/ /** 前台调用 * 每次调用$()创建库对象,使其每次调用都是独立的对象 * $()创建库对象,有一个可选参数,参数有两种方式,1是传入的this,2是传入的字符串 * 可选参数说明: * 传入的this,this,就是当前对象本身 * * 传入的字符串,代表获取元素选择器 * 参数是元素选择器(id值.class值.标签名称)其中一样的字符串

第一百六十一天 how can I 坚持

突然感觉好恐怖啊. 人生三万来天,每天记一篇日记,三万来篇,就是能坚持下来,好像也没什么意义啊.oncelife意义何在? 到底人活这一世的意义是什么?悟... 今天同事问了几个很基础的问题,都不知道.哎... 一天天.. 我相信总有一天,我会觉醒. 其实不是不能成功,只是你不想成功,真的是这样.. 睡觉.