一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php留言板程序(适合php初学者)

时间:2010-07-24 编辑:简简单单 来源:一聚教程网

 代码如下 复制代码





所有留言
css教程" href="style.css" media="all" />


发表留言
require('common.php');
$result = mysql教程_query("select * from gb_content order by id desc");//查询数据

while ($row = mysql_fetch_array($result, mysql_both)) {// 取一条数据
?>


 
   
 
 
   
 
 
   
 
[] 发表于:
修改 删除

}

mysql_free_result($result);

?>

 

 
增加留言程序

 

 代码如下 复制代码

require('common.php');
if ($_get['action']=='save') {
 // 清除空格
 $_post['username'] = trim($_post['username']);
 $_post['content'] = trim($_post['content']);
 if (!get_magic_quotes_gpc()) {// 如果魔术引号关闭使用addslashes转换
  $_post['username'] = addslashes($_post['username']);
  $_post['content'] = addslashes($_post['content']);
 }
 // 判断表单是否全部填写
 if (!$_post['username'] || !$_post['content']) {
  echo '请输入用户名和内容!';
  exit;
 }
 // 判断用户名是否超出长度
 if (strlen($_post['username'])>16) {
  echo '用户名超出长度!';
  exit;
 }
 // 判断内容是否超出长度
 if (strlen($_post['content'])>255) {
  echo '内容超出长度!';
  exit;
 }

 // insert sql语句
 $sql = "insert into gb_content (username,content,insert_time)
   values ('".$_post['username']."','".$_post['content']."','".date('y-m-d h:i:s')."')";
 mysql_query($sql,$link);// 执行sql查询
 echo '添加成功! 查看留言';
 exit;
}
?>




提交留言



 
   
 
 
   
 
[提交留言]

       
         
           
           
         
         
           
           
         
           
           
         
       
用户名:
内容:
           

     


 

 
//删除留言

 

 代码如下 复制代码

 require ("common.php");
 mysql_query('delete from gb_content where id='.intval($_get["id"]));
 echo '已删除!查看留言';
?>

 

 
commond1.php

 

 

 代码如下 复制代码

 class mysql{
  private $host;
  private $name;
  private $passwd;
  private $databass;
  private $ut;
  //初始化
  function __contruct( $host,$name,$passwd,$databass,$ut){
   $this->host=$host;
   $this->name=$name;
   $this->passwd=$passwd;
   $this->databass=$databass;
   $this->ut=$ut;

  }

  function connect(){
   $conn=mysql_connect($this->host,$this->name,$this->passwd) or die ("数据库教程连接失败!".mysql_error());
   mysql_select_db($this->databass,$conn) or die ("没有数据库".$this->databass);
   mysql_query("set names='$this->ut'");


  }


  function query($sql){

   return mysql_query($sql);

  }

  function fetch_array($query){

   return mysql_fetch_array($query);

  }

  function nun_row($query ){
   return mysql_num_row($query);
  }

   function  close(){
    mysql_close();
   }
   function fn_insert($table ,$name,$value ){
    $this->query("insert into $table ($name) value ($value)");

   }
  function fn_update($table,$new,$if){
   $this->query("update $table set $new where $if");
  }

  function fn_del($table,$if ){
   $this->query("del from $table where $if");
  }

 }

热门栏目