Hey there Perl Community, this is my first question here in this community. Actually im sitting in front of a webpage which im trying to get to work on time. This Webpage is to show the dynamic color changes of a website if a user makes an input on the site. Within this page i made a History Table to show me my latest colorpicks i entered in the last times. This is my perl sourcecode:
#!/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 LIM +IT 1"; my $sth = $dbc->prepare($sql); # # execute the query # $sth->execute(); # while(@row = $sth->fetchrow_array()) { # print "<tr id='tbl_row'><td>$row[1]</td>"; # print "<td style='background-color: $row[0]'>$row[0]</td></ +tr>"; # } # $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 LIMI +T 10"; my $sth = $dbc->prepare($sql); # execute the query $sth->execute(); print "<div id='historytable' type='text' style='position: fixed +; top: 0px; width: 300px; height: 100%; background-color: #eee; margi +n-left: 0%; margin-top: 0px'> <input id='hsufu' type='text' name='hsufu'></input> <table id='table'>"; while(@row = $sth->fetchrow_array()) { print "<tr id='tbl_row'><td>$row[1]</td>"; print "<td style='background-color: $row[0]'>$row[0]</td></tr +>"; } print "</tr></table></div>"; $sth->finish(); } my $html = qq( <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www. +w3.org/TR/html4/strict.dtd"> <html> <head> <title>Dynamische Farbänderung</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5 +.2/jquery.min.js"></script> <script src="js/changecolor.js"></script> <link rel="stylesheet" href="css/changecolor.css"> </head> ); $html .= qq( <body style="background-color: $id"> <div id="formular"> <h1 id="h1" style="color: $id">Testaufgabe</h1> <h2 id="h2" style="color: $id">Dynamische HintergrundFarben Än +derung</h2> <input autofocus id='hexadezimal' type='text' name='hexadezi +mal'> </div> </body> </html> ); # Params #$id = $cgi->param('hexcode'); print $cgi->header(-charset => 'utf-8'); history_table($dbc); print $html; print $color;
My question now: How is it possible to get myself the color from the MYSQL Table without reloading my perl document? Especially this code i thought get myself my variables on demand. But right it crashes when i make a reload.
$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 LIM +IT 1"; my $sth = $dbc->prepare($sql);
Kind regards Daniel

In reply to Print my latest MySQL Entries without page reload by TheRod1990

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.