Editing Records
This module lets you edit entries that are already in the database. This can be useful if a previous entry had an error.
Overview
The edit operation takes place in several steps:
- Display an edit icon on any search results page. Clicking on the edit (pencil) icon brings up the edit page for that database record. The record is referenced by its ID field in the database.
- Display the current data for the selected record in a form. The form is similar to
the form for adding a record, with two modifications:
- The form has a hidden form field that holds the ID for the record.
- The other form fields are populated with the current data for this record.
- The user can change the data, then click on the Submit button.
- The form handler creates a MySQL UPDATE query that changes the data.
Perl modules
The edit function uses two different Perl modules to perform all its activities:
- edit.pl displays the form that lets the user enter new data. This form must be a Perl module because it queries the database to obtain the current data for this record.
- editfnish.pl is the form handler for this form. It does four things:
- Obtain the current data for this record.
- Perform the update query that changes the data.
- Obtain the data for this record after the change.
- Display the old data and the new data side by side for verification purposes.
Outline
Here is an abbreviated outline of the MySQL commands that make this happen:
# Get the values BEFORE update so we can compare # my $sql = "SELECT * FROM gen44_rom WHERE ID = $id;"; my $oldvalues = $sth->fetchrow_hashref; # Do the update # $sql = "UPDATE gen44_rom SET DanceName='$dance', Rhythm='$rhythm', Phase='$phase', " . " Choreographer='$choreo', Label='$label', Record='$record', Year='$year', " . " MonthNum='$monthNumber', Month='$month', Extra='$extra' WHERE ID=$id; "; # Get the values AFTER update so we can compare # my $sql = "SELECT * FROM gen44_rom WHERE ID = $id;"; my $newvalues = $sth->fetchrow_hashref; # Display the values side by side for verification # print ("\n"); print_table_row ("Dance Name", $oldvalues->{"DanceName"}, $newvalues->{"DanceName"}); print_table_row ("Rhythm", $oldvalues->{"Rhythm"}, $newvalues->{"Rhythm"}); print_table_row ("Phase", $oldvalues->{"Phase"}, $newvalues->{"Phase"}); # and so on ... and so on ... and so on ... Field Old Value New Value