N
Nikos
You understand very quickly what i wanted to do and you helped me write
the correct way.
After all of the guys suggestions here is how the script transformed:
=========================================================
my $script = param('select') || "Welcome Page!";
my ($data, @data);
if (param('select') and param('select') ne '..')
{
open(FILE, "<../data/text/$script.txt") or die $!;
@data = <FILE>;
close(FILE);
$data = join('', @data);
$dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host'"
) or die $dbh->errstr;
}
else
{
$sth = $dbh->prepare( "SELECT host FROM guestlog WHERE host=?" );
$sth->execute($host);
if ($sth->rows)
{
$sth = $dbh->prepare( "UPDATE guestlog SET
hostcount=hostcount+1 WHERE host=?" );
$sth->execute($host);
$sth = $dbh->prepare( "SELECT * FROM guestlog WHERE host=?" );
$sth->execute($host);
$row = $sth->fetchrow_hashref;
$data = "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçÃ
óåëßäá Ã¥ÃäéáöÃñïõóá!\n" .
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{date}. " !!\n" .
"ÓýÃïëéêÃò Þñèåò åäþ " .$row->{hostcount}. " öïñÃò!!!\n" .
"Ôåëåõôáßá åßäåò ôï êåßìåÃï { " .$row->{script}. " }\n" .
"Ãïéü êåßìåÃï èá ìåëåôÞóåòé áõôÞà ôçà öïñÜ !?";
}
else
{
if ($host ne "Ãßêïò")
{
$data = "ÃåéÜ óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù Ãá âñåßò ôá êåßìåÃá Ã¥ÃäéáöÃñïÃôá ";
$sth = $dbh->prepare("SELECT * FROM guestlog WHERE host=?");
$sth->execute($host);
$sth = $dbh->prepare( "INSERT INTO guestlog (host, date,
script, hostcount, pagecount) VALUES (?, ?, ?, ?, ?)" );
$sth->execute($host, $date, $script, $hostcount, $pagecount);
}
else
{
$data = "ÃåéÜ óïõ Ãéêüëá, ôé ÷áìðÜñéá?! ¼ëá äåîéÜ Ãá óïõ
ðÜÃÃ¥ ðÜÃôá! ;-)";
}
}
}
=========================================================
I wish i can test ti but iam currently having a mysql problem but thing
it will work
If we still can make it shorter please let me know!
the correct way.
After all of the guys suggestions here is how the script transformed:
=========================================================
my $script = param('select') || "Welcome Page!";
my ($data, @data);
if (param('select') and param('select') ne '..')
{
open(FILE, "<../data/text/$script.txt") or die $!;
@data = <FILE>;
close(FILE);
$data = join('', @data);
$dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host'"
) or die $dbh->errstr;
}
else
{
$sth = $dbh->prepare( "SELECT host FROM guestlog WHERE host=?" );
$sth->execute($host);
if ($sth->rows)
{
$sth = $dbh->prepare( "UPDATE guestlog SET
hostcount=hostcount+1 WHERE host=?" );
$sth->execute($host);
$sth = $dbh->prepare( "SELECT * FROM guestlog WHERE host=?" );
$sth->execute($host);
$row = $sth->fetchrow_hashref;
$data = "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçÃ
óåëßäá Ã¥ÃäéáöÃñïõóá!\n" .
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{date}. " !!\n" .
"ÓýÃïëéêÃò Þñèåò åäþ " .$row->{hostcount}. " öïñÃò!!!\n" .
"Ôåëåõôáßá åßäåò ôï êåßìåÃï { " .$row->{script}. " }\n" .
"Ãïéü êåßìåÃï èá ìåëåôÞóåòé áõôÞà ôçà öïñÜ !?";
}
else
{
if ($host ne "Ãßêïò")
{
$data = "ÃåéÜ óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù Ãá âñåßò ôá êåßìåÃá Ã¥ÃäéáöÃñïÃôá ";
$sth = $dbh->prepare("SELECT * FROM guestlog WHERE host=?");
$sth->execute($host);
$sth = $dbh->prepare( "INSERT INTO guestlog (host, date,
script, hostcount, pagecount) VALUES (?, ?, ?, ?, ?)" );
$sth->execute($host, $date, $script, $hostcount, $pagecount);
}
else
{
$data = "ÃåéÜ óïõ Ãéêüëá, ôé ÷áìðÜñéá?! ¼ëá äåîéÜ Ãá óïõ
ðÜÃÃ¥ ðÜÃôá! ;-)";
}
}
}
=========================================================
I wish i can test ti but iam currently having a mysql problem but thing
it will work
If we still can make it shorter please let me know!