#!/usr/bin/perl #!c:\Perl\bin\perl.exe use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use lib qw(/path/to/lib_dev); use CGI::Simple; use CGI::Session; # v4.13 (was v3.11) use HTML::Template; use DBI; # v1.32 my $q = CGI::Simple->new() or die "can't create query object: $!"; my $dbh = DBI->connect('DBI:mysql:database=mydb;host=myhost', 'myuid', 'mypwd') or die "can't connect to db"; my $sid = $q->cookie("CGISESSID") or undef; my $s = CGI::Session->new(undef, $sid, {Handle => $dbh}) or die CGI::Session->errstr; # corrected $_ = $q->param('a'); if (/next/) { next_page() } elsif (/prev/) { previous_page() } else { first_page() } sub next_page { my $first = $s->param('f'); $first += 20; $s->param('f', $first); print_output($first); } sub previous_page { my $first = $s->param('f'); $first -= 20; $s->param('f' => $first); print_output($first); } sub first_page{ $s->param('f', 0); print_output(0); } sub print_output { my ($first) = @_; my $file = 'tmpl/session.html'; my $t = HTML::Template->new( filename => $file ) or die "can't find $file: $!"; $t->param({first => $first}); print $s->header; print $t->output; }