文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>简单的php留言本

简单的php留言本

时间:2007-04-06  来源:mickey_ice

今天终于完成一个简单的PHP留言本
功能:1.显示留言(姓名和留言)
     2.写留言
     3.将留言插入数据库
数据库:
create database test;
create table contents(id int(11) not null auto_incremnet,
                      name varchar(20) not null default '"no name"',
                      content mediumtext not null,
                      primary key(id))type=myisam auto_increment = 6;

index.php
$exec = "select name,content from contents order by id asc";
$result = mysql_query($exec);
while($rs = mysql_fetch_object($result))
{
  echo"姓名:".$rs->name."";
  echo"留言:".$rs->content."";
}
?>
姓名:
留言:


updata.php

//2007-4-27增加判断并捕捉异常,有待完善
function filled_out($form_vars)   //判断客户端传过来的参数是否全部填写
{
  foreach($form_vars as $key=>$value)
  {
   if(!isset($key)||($value ==''))
    return false;
  }
  return true;
}
try
{
if(!filled_out($_POST))
{
  throw new Exception( 'you have not filled the form out correctly'.'please go back and try again');
}
}
catch(Exception $e)
{
  echo $e->getMessage();
  exit;
}
//-------------------------------//
$conn = mysql_connect("localhost","user","password");
mysql_select_db("test");
    mysql_query("set names utf-8");
$exec = "insert into contents(name,content) values('".$_POST['username']."','".$_POST['content']."')";
$result = mysql_query($exec);
?>
//------2007-04-28--------//
//处理完数据后直接定位到显示页面,自动刷新
                  
                  
//------------------------//
返回
这是学习php以来的第一个完整页面,以后将继续努力,添加更多功能:(在客户端和服务器端分别对表单变量做不同的判断070427;添加验证码;自动刷新页面070428;分页)


相关阅读 更多 +
排行榜 更多 +
开心动动脑安卓版 v1.0 手机版

开心动动脑安卓版 v1.0 手机版

休闲益智 下载
不良人破局手游下载

不良人破局手游下载

角色扮演 下载
云海之下手游下载

云海之下手游下载

角色扮演 下载