Chinaunix首页 | 论坛 | 博客
  • 博客访问: 617922
  • 博文数量: 184
  • 博客积分: 10057
  • 博客等级: 上将
  • 技术积分: 2505
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-31 16:34
文章分类

全部博文(184)

文章存档

2010年(5)

2009年(104)

2008年(75)

我的朋友

分类:

2009-09-30 19:35:25

HTML代码:




留言本--显示页面

留言本内容显示


[% FOREACH item IN Message %]
留言者:[% item.user %]

留言信息:[% item.info %]


[% END %]

 

Perl代码:
#!/usr/bin/perl
use DBI;
use CGI ':standard';
use Template;
BEGIN{
        use CGI::Carp qw(fatalsToBrowser carpout);
}

my @myarray;
$db=DBI->connect('DBI:mysql:sample_db;user=root');
        if (param()){
        $username=param('username');
        $info=param('info');
        $sth=$db->prepare("insert into test(user,info) values(?,?)")
        or die "Can't prepare sql statement".DBI->errstr;
        $sth->execute($username,$info);
        $sth=$db->prepare("select user,info from test ")
        or die "Can't prepare sql statement".DBI->errstr;
        $sth->execute();
        if($sth->rows==0){
                print "No date";
                exit;
        }
        while(my @val=$sth->fetchrow_array()){
                push @myarray, { user => $val[0], info => $val[1] };
                }
        $sth->finish();
        $db->disconnect();
        }
        else{
        print "Sorry!";
}
my $config = {
        INCLUDE_PATH => 'ttdir',
    };
my $vars = {
        Message => \@myarray,
 };
my $input = 'post.tt';
my $tt = Template->new($config)||die "$Template::ERROR\n";
print header(-type=>'text/html',-charset=>'gb2312');
$tt->process($input,$vars) || die $tt->error(), "\n";
阅读(1332) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~