#!/usr/bin/perl -w
use CGI qw/:standard/;
use DBI;
my $cgi = new CGI;
my $DBNAME = "jejeno";
my $DBHOST = "sql24.webhuset.no";
my $DBUSERNAME = "jejeno";
my $DBPASSWORD = "lBEvGCx9t";
print("Content-type: text/html\r\n\r\n");
# Data from user..
if($cgi->param('id')) {
my $id = $cgi->param('id');
setHits($id);
getPage($id);
} else {
print "\n";
}
# Function setHits updates the sql with count of hits..
sub setHits {
my ($id) = @_;
my $query = "UPDATE link SET hits = hits + 1 WHERE id=$id;";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$dbh->disconnect;
}
# Function getPage gets the selected page..
sub getPage {
my ($id) = @_;
my $query = "SELECT url FROM link WHERE id=$id;";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$url);
$sth->fetch();
print "\n";
$sth->finish();
$dbh->disconnect;
}