#!/usr/bin/perl -w use CGI; use warnings; use strict; use DBI; #use System::Timeout qw(system); my $cgi = CGI->new; my $color; my $history; my $table = "DBI:mysql:colorchanger"; my $username = "root"; my $password = ''; my %error = (PrintError=>0, RaiseError=>1); my $dbc = DBI->connect($table,$username,$password, \%error); #MYSQL Abfrage: Den letzten Werte us der Datenbank. # Params my $id = $cgi->param('hexcode'); if (defined $id) { $dbc->do( "INSERT INTO color02 ( hexcode ) VALUES ( ? )", undef, $id ); #my $db_result = $dbc->prepare('SELECT hexcode FROM color02 ORDER BY id DESC LIMIT 1'); #$db_result->execute() or die $db_result->err_str; my ($dbc) = @_; my @row; my $sql = "SELECT hexcode, ts FROM color02 ORDER BY id DESC LIMIT 1"; my $sth = $dbc->prepare($sql); # # execute the query # $sth->execute(); # while(@row = $sth->fetchrow_array()) { # print "$row[1]"; # print "$row[0]"; # } # $sth->finish(); } my $db_result = $dbc->prepare('SELECT hexcode FROM color02 ORDER BY id DESC LIMIT 1'); $db_result->execute() or die $db_result->err_str; while (my @row = $db_result->fetchrow_array()) { $id = $row[0]; } sub history_table { my ($dbc) = @_; my @row; my $sql = "SELECT hexcode, ts FROM color02 ORDER BY id DESC LIMIT 10"; my $sth = $dbc->prepare($sql); # execute the query $sth->execute(); print "
"; while(@row = $sth->fetchrow_array()) { print ""; print ""; } print "
$row[1]$row[0]
"; $sth->finish(); } my $html = qq( Dynamische Farbänderung ); $html .= qq(

Testaufgabe

Dynamische HintergrundFarben Änderung

); # Params #$id = $cgi->param('hexcode'); print $cgi->header(-charset => 'utf-8'); history_table($dbc); print $html; print $color; #### $dbc->do( "INSERT INTO color02 ( hexcode ) VALUES ( ? )", undef, $id ); #my $db_result = $dbc->prepare('SELECT hexcode FROM color02 ORDER BY id DESC LIMIT 1'); #$db_result->execute() or die $db_result->err_str; my ($dbc) = @_; my @row; my $sql = "SELECT hexcode, ts FROM color02 ORDER BY id DESC LIMIT 1"; my $sth = $dbc->prepare($sql);