jaacmmason has asked for the wisdom of the Perl Monks concerning the following question:
The code for the new screen (modify.pl) is as follows: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="AssetTag" value="$row->{AssetTa +g}"> <input type="submit" name="modify" value="Modify" style="font- +size +:15px"/> </form> </td></tr>!; $i++; } } } else { $results .= "<b>No results matched your asset query.</b>"; }
I am trying to use the AssetTag field that I THINK is being sent via the POST in order to read the database and populate the few fields on the screen. After this I need to be able to modify and then have a “Save” button to update the SQL database with the modified information from the user. I am doing this in baby steps as I am still pretty new to PERL. Thank you for any suggestions, comments, and ideas I may get on resolving this!!!#!perl use DBI; use CGI; my $assetTag = param('AssetTag'); print "Content-Type: text/html\n\n"; $head = <<'HEAD'; <html> <head> <title>Inventory Edit</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 Edit</font></h1> <p>This page allows you to edit the Branch Inventory.</p></div> <div style="font-size:18px;letter-spacing:5px;padding-top:5px;text-ali +gn:center;background:#F9F9DD;width:100%;"> <form action="http://webnm/cgi-bin/Modify.pl" method="get"> <Table> <tr> <td>Asset Tag</td> <td><input style="font-size:15px;" type="text" name="asset +tag"/></td></tr> <tr> <td>SerialNumber</td> <td><input style="font-size:15px;" type="text" name="Seria +lNumber"/></td></tr> <tr> <td>AssetType</td> <td><input style="font-size:15px;" type="text" name="Asset +Type"/></td></tr> <tr> <td>Branch</td> <td><input style="font-size:15px;" type="text" name="Branc +h"/></td></tr> <tr> <td>Status</td> <td><select name="Status" id="Status"> <option value="Inventory">Inventory</option> <option value="Production">Production</option> <option value="Testing">Testing</option> </td></tr> </table> </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(); $field = $c->param("field"); $field =~ s/'/\\'/; $h = DBI->connect("dbi:mysql:inventory:localhost","ID","PW") or die("c +ouldn’t connect to database"); $query = "SELECT SerialNumber, AssetTag, AssetType, Branch, Status, FR +OM inv WHERE AssetTag = $AssetTag"; $q = $h->prepare($query); %columns = ( SerialNumber => "Serial Number", AssetTag => "Asset Tag", AssetType => "Asset Type", Branch => "Branch", Status => "Status", ); $results .= "</tr>"; $h->disconnect(); $results .= <<'RESULTS'; </table> </div> RESULTS print $head; print $body; print $results; print $tail;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Editing Data in SQL database
by CountZero (Bishop) on Mar 01, 2011 at 19:37 UTC | |
by cavac (Prior) on Mar 01, 2011 at 22:53 UTC |