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:

  1. 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.
  2. 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.
  3. The user can change the data, then click on the Submit button.
  4. 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:

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 ("FieldOld ValueNew Value\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 ...