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

In reply to Re: Update mysql table with button on corresponding row by blue_cowdawg
in thread Update mysql table with button on corresponding row by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.