473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ


Modifying Records Part 1

By Blair Ireland
Senior Editor, TheScripts.com

All databases sadly need this function.... but since we already passed the hard stuff long ago, this shouldn't be too tough if you have that ever-so-needed caffeine in your blood. I don't care what time it is, caffeine helps.

Anyways, enough chit-chat and babbling.... time to get to what you came for. Me telling you about my life. No wait, coding a database, thats it....

Back to that sea of ifs....... lets find out what the controls are for modifying data.

elsif ($form{'action'} eq "edit") {
    &edit;
}

Hmm.... looks like its time to lug ourselves over to the sub &edit.

sub edit {
     &header("Search To Edit");
     &search_form("edit_two","To Edit");
     &footer;
}

Oh this is a treat. Not only do we understand all of these sub procedures here, but we just used them in sub delete_record.

The only difference is that instead of using the word "Delete", we are using edit here, as it this part only confronts you with a search form, created by &search_form.

The action field has a value of 'edit_two' now in the search form, so we have to find the controls for that value now in those if statements.

elsif ($form{'action'} eq "edit_two") {
    &edit_two;
}

Notice a trend here? I use actions with a value the same as the sub they will be calling. This is just so I can read it better, but I would recommend it.

sub edit_two {
    my (@results) = &search;

Here are those search results again, produced by &search. They are once again put into @results, a my variable.

    $search_num = @results;

I sure hope you know what this means, as its not the first time we've used it. Otherwise, jump back into the innards of this tutorial and read up on it.

    if ($search_num < 1) { &nomatches; }

Makes sense still? Good.

    elsif ($search_num > 0) {
         &multi_match("radio","edit_three","Edit",@results);
    }

Here is the only real difference. Since we only want the user to be able to edit one record at a time, we send it the 'radio' button specification. The action value is set to 'edit_three'. The 'Edit' parameter is just for formatting (the text), and lastly, we send in the search results.

}

« Deleting Records Part 3 Modifying Records Part 2 »

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.