ejx2 has asked for the wisdom of the Perl Monks concerning the following question:
I'm very new to perl, infact this is my first accomplishment so far. So, please bear with me while I try to learn from the best.
My question is how can I change this script to allow my users to edit the data they posted? For example if one of my analysts forget to add a comment or make a typo, I'd like them to be able to click a link, on the page that contains the post, edit the content and then click "save" or "resubmit".
#!/usr/bin/perl -w use strict; use CGI qw(:standard); use DBI; print header, start_html("Daily Communication Log"); print "<a href = /form.html>Submit New Log Entry</a><br><br>"; # Declare variables my ( $analyst, # name of the analyst making the entry $name, # name from combo box on html form $shift, # shift analyst is on $cust, # new customer turn up $issues, # customer specific issues analysts should be aware of $eoi, # events that require observation $message, # general comments not related to previous fields $cur, # keeps current entries $dbh, # database handler $filter, # escapes single quote $sql, # handles statements $stq, # does query ); $cur = CGI->new(); #hold current request $message=$cur->param("message"); $cust=$cur->param("cust"); $issues=$cur->param("issues"); $eoi=$cur->param("eoi"); $analyst=$cur->param("analyst"); ($shift,$name)=split(/:/,$analyst); # Connect to Database $dbh = DBI->connect("DBI:mysql:dcl:localhost","user","passwd"); if ($message) { # SQL Statement $stq = $dbh->prepare( qq{ insert into dcl_log values(now(),"$name","$s +hift","$cust","$issues","$eoi","$message") }); $stq->execute || print "Unable to execute MySQL statement"; } # Execute query and print after values have been entered # Need to see the last 5 entires in reverse order $sql = "select * from dcl_log order by timestamp desc limit 5"; $stq = $dbh->prepare($sql); $stq->execute || print "Could not complete SQL statement ... check syntax." +; # Output results my @row; while (@row=$stq->fetchrow_array) {table_data (@row);} $dbh->disconnect(); print end_html; sub table_data { my @data = @_; my %D; print "<center><table border=0 width=100%>"; $D{'time'} = $data[0]; $D{'name'} = $data[1]; $D{'shift'} = $data[2]; $D{'cust'} = $data[3]; $D{'issues'} = $data[4]; $D{'eoi'} = $data[5]; $D{'message'} = $data[6]; print "<tr><td colspan=2 align=center><b>$D{'time'}</b></td></tr>\n"; print "<tr><td width=1% align=left><b>Name:</b>\n"; print "<td align=left>$D{'name'}</td></tr>\n"; print "<tr><td align=left><b>Shift:</b>\n"; print "<td align=left>$D{'shift'}</td></tr>\n"; print "<tr><td align=left><b>Customer:</b></td></tr>\n"; print "<tr><td colspan=2 align=left>$D{'cust'}</td></tr>\n"; print "<tr><td align=left><b>Issues:</b></td></tr>\n"; print "<tr><td colspan=2 align=left>$D{'issues'}</td></tr>\n"; print "<tr><td align=left><b>EOI:</b></td></tr>\n"; print "<tr><td colspan=2 align=left>$D{'eoi'}</td></tr>\n"; print "<tr><td align=left><b>Message:</b></td></tr>\n"; print "<tr><td colspan=2 align=left>$D{'message'}</td></tr>\n"; print "</table></center><hr>\n"; }
janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Editing Posted Data
by Tanktalus (Canon) on Jul 08, 2005 at 03:15 UTC | |
|
Re: Editing Posted Data
by neniro (Priest) on Jul 08, 2005 at 08:07 UTC |