• 简单的PHP留言本


    config.php

    <?php
    	$conn = @mysql_connect("localhost","root","") or die("数据库连接出错!");
    	mysql_select_db("gb",$conn);
    	mysql_query("set names 'GBK'");
    
    ?>
    

    add.php

    <?php
    	include("config.php");
    	
    if($_POST['submit']){
    //在这里的时候,忘记message里还有个字段lastdate没有写,导致插入数据不成功。找了好久才找出错误。 
    	$sql="insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
    	
    	mysql_query($sql);
    	echo "成功";
    }
    ?>
    <form action="add.php" method="post">
    用户:<input type="text" name="user" /><br>
    标题:<input type="text" name="title" /><br />
    内容:<textarea name="content"></textarea><br />
    <input type="submit" name="submit" value="提交" />
    </form>
    view.php
    <?php
    include("config.php");
    ?>
    <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
    <?php
    $sql="select * from message order by id desc";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query)){
    ?>
    //NND。我在wampserver默认环境下,使用<?=$row[title]?>这种语法,就是读取不出内容来。非要用这种才可以。郁闷。又是好久才琢磨出来
      <tr bgcolor="#eff3ff">
      <td>标题:<?php echo $row[title];?> 用户:<?php echo $row[user];?></td>
      </tr>
      <tr bgColor="#ffffff">
      <td>内容:<?php echo $row[content];?></td>
      </tr>
      <?php
      }
      ?>
    </table>
    
    然后还有个数据库的SQL。
    CREATE TABLE `message` (
      `id` tinyint(1) NOT NULL auto_increment,
      `user` varchar(25) NOT NULL,
      `title` varchar(50) NOT NULL,
      `content` tinytext NOT NULL,
      `lastdate` date NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
    
  • 相关阅读:
    Java 并发核心编程
    JavaScript中的类型(二)
    IEEE 754 规定的双精度浮点数表示
    javascript 上传多个附件(struts)
    给自己放放松
    C语言快速排序
    Mac付费软件免费获取
    Keil4 uVision软件生成hex文件
    Mac苹果电脑安装虚拟机
    数据结构是什么
  • 原文地址:https://www.cnblogs.com/blueness/p/1730012.html
Copyright © 2020-2023  润新知