Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Update mysql table with button on corresponding row

by blue_cowdawg (Monsignor)
on Feb 11, 2013 at 16:21 UTC ( #1018173=note: print w/replies, xml ) Need Help??

in reply to Update mysql table with button on corresponding row

      I dont really understand CGI that well and could use some help.

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 => "" ); 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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018173]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2018-06-19 22:49 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (115 votes). Check out past polls.