jaacmmason has asked for the wisdom of the Perl Monks concerning the following question:

Good afternoon. I have some code that displays data from a MySQL databason on screen. I want to modify this code to not only display the data, but add a edit button at the end of each displayed line that will allow a user to select it and be directed to another page that will allow them to modify the row of data in the database. So far I have been unsuccessful at adding the button and getting it to open a new page. Can anyone help me on correct placement of this button, and how I go about opening a new update page? I have removed all code I have been working with to get this done and am back at square one. This is the current code that will allow the display on screen:
#!perl use DBI; use CGI; print "Content-Type: text/html\n\n"; $head = <<'HEAD'; <html> <head> <title>Branch Inventory Lookup</title> </head> <body style="font-size:11px;font-family:tahoma;background:#F9F9DD;padd +ing:0;margin:0;"> HEAD $tail = <<'TAIL'; </body> </html> TAIL $body = <<'BODY'; <div style="padding-left:20px;padding-top:10px;background:#F9F9DD;"><h +1><font color="#006600"> Branch Inventory Query</font></h1>div> <div style="font-size:18px;letter-spacing:5px;padding-top:15px;text-al +ign:center;background:#F9F9DD;width:100%;"> <form action="http://hmDir/cgi-bin/Inventory.pl" method="get"> <select style="font-size:15px;" name="field"> <option value="Branch">Branch</option> <option value="AssetTag">Asset Tag</option> <option value="SerialNumber">Serial Number</option> <option value="Status">Status</option> <option value="AssetType">Asset Type</option> </select> <select name="likeEquals" style="font-size:15px;"> <option value="=">=</option> <option value="LIKE">LIKE</option> </select> <input style="font-size:15px;" type="text" name="searchTerm"/> <input style="font-size:15px;" type="submit" name="search" value=" +Search"/> </form> </div> <div style="font-size:18px;letter-spacing:5px;padding-top:15px;padding +-right:20px;text-align:right;background:#F9F9DD;width:100%;"> <form method="get"> <input type="button" value="Print" onclick="window.print()" /> </form> </div> BODY $results = <<'RESULTS'; <div style="padding:5px;position:absolute;top:275px;height:100px;width +:100%;background:#F9F9DD;"> <table cellspacing="0" cellpadding="3" style="padding:5px;font-size:11 +px;border:1px black solid;" bgcolor="#EEEEEE" width="100%"> RESULTS $i = 0; $c = new CGI(); $searchTerm = $c->param("searchTerm"); $likeEquals = $c->param("likeEquals"); $field = $c->param("field"); $searchTerm =~ s/'/\\'/; $likeEquals =~ s/'/\\'/; $field =~ s/'/\\'/; if($searchTerm eq "") { $searchTerm = "void"; } $h = DBI->connect("dbi:mysql:inventory:localhost","ID","PW") or die("c +ouldnt connect to database"); $query = "SELECT SerialNumber, AssetTag, AssetType, Branch, Status, Co +mments FROM assets WHERE $field $likeEquals ? ORDER BY AssetType"; $q = $h->prepare($query); $rows = $q->execute($searchTerm); %columns = ( SerialNumber => "Serial Number", AssetTag => "Asset Tag", AssetType => "Asset Type", Branch => "Branch", Status => "Status", Comments => "Comments", ); if($rows > 0) { $results .= "<tr><td colspan='6'>Your search for <b>$searchTerm</b> in + <b>$columns{$field}</b> returned <b>$rows</b> result(s).</td></tr>"; $results .= "<tr style='background:black;color:white;font-weight:900;' +>"; foreach $field (@{$q->{NAME}}) { $results .= "<td width='50'>$columns{$field}</td>"; } $results .= "</tr>"; if($c->param("searchTerm")) { while ($row = $q->fetchrow_hashref) { if($i % 2 == 0) { $results .= "<tr style='height:30px;border-bottom:1px;'><t +d>$row->{SerialNumber}</td><td>$row->{AssetTag}</td><td>$row->{AssetT +ype}</td><td>$row->{Branch}</td><td>$row->{Status}</td><td>$row->{Com +ments}</td></tr>"; } else { $results .= "<tr style='height:30px;border-bottom:1px;back +ground:#DDD;'><td>$row->{SerialNumber}</td><td>$row->{AssetTag}</td>< +td>$row->{AssetType}</td><td>$row->{Branch}</td><td>$row->{Status}</t +d><td>$row->{Comments}</td></tr>"; } $i++; } } } else { $results .= "<b>No results matched your Inventory query.</b>"; } $h->disconnect(); $results .= <<'RESULTS'; </table> </div> RESULTS print $head; print $body; print $results; print $tail;
Thanks in advance for any help I may receive on how to add buttons after each displayed line of data from the query results.

Replies are listed 'Best First'.
Re: Adding command button to selevt a value
by poj (Abbot) on Feb 11, 2011 at 15:42 UTC

    If the SerialNumber is unique then just add a form to each row with that as a hidden value

    if($c->param("searchTerm")) { while ($row = $q->fetchrow_hashref) { my $bgc = ($i % 2 == 0) ? 'background:#DDD;' : ''; $results .= qq!<tr style="height:30px;border-bottom:1px;$bgc"> <td>$row->{SerialNumber}</td> <td>$row->{AssetTag}</td> <td>$row->{AssetType}</td> <td>$row->{Branch}</td> <td>$row->{Status}</td> <td>$row->{Comments}</td> <td> <form method="post" action="modify.pl"> <input type="hidden" name="SerialNumber" value="$row->{SerialNumbe +r}"> <input type="submit" name="modify" value="Modify" style="font-size +:15px"/> </form> </td></tr>!; $i++; } }
    poj
      THANK YOU! This was what I was looking to accomplish!