http://www.perlmonks.org?node_id=1018173


in reply to Update mysql table with button on corresponding row

Not too sure how we are supposed to help you. You seem to have some primitive knowledge of how to make Perl scripts talk to a database, but other than the button I see no input to be processed.

Let me elaborate a bit on a response to this you got earlier: Take a look at CGI, take a step back, and work on some of the examples given in the documentation to learn the CGI half of this.

Once you understand thoroughly who to create a form, submit the inputs to a back end CGI script you can then move on to do what is known as CRUD which is short hand for Create Retrieve, Update and Delete operations.

Most databases that I've ever worked on have unique ids for the rows contained within a table. You can use that very much to your advantage. Take a look at this code sniglet:

use CGI qw/:all/; | much handwaving | foreach my $row ($dbh->fetchrow_hashref){ print start_form ( -action => "crudscript.pl" ); print hidden('row_id',$row->{row_id}); printf "Old Name: %s",$row->{name}; printf "New Name: %s",texfield('newname',''); printf submit('action','delete'); printf submit('action','update'); print "<br>"; }
That will produce a form with a bunch of rows displayed with the corresponding values. A text input will be present for each row and you can write a script that checks to see what is to be done with the input. For instance:
#!/usr/bin/perl -w use strict; use feature 'switch'; #only works in newer versions (5.10?) of Perl use CGI qw/ :all /; | | Handwaving here. | my $cgi=CGI->new(); my $action = $cgi->param('action'); given ($action){ when('delete'){ my $row_id = $cgi->param('row_id'); | insert code here to delete a row based on its id } when('update'){ my $newname = $cgi->param('newname'); if ($newname) { # non-null input only | code here to execute update } | }

You got a lot of work to do to get to that point though in terms of learning. Get started! :-)


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: Update mysql table with button on corresponding row
by Anonymous Monk on Feb 11, 2013 at 18:20 UTC
    Thank you, this is very helpful!