Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am a new perl programmer using CGI.pm to create my application.
I have a subroutine defaultNewInvest() that creates a form that users can input some data. (The form has been truncated.) I would like to be able to search the database and retrieve the information INTO THE SAME FORM so that changes can be made.
I have no trouble creating the form, inserting the data into an Oracle database, nor retrieving the names into a list. If I click on the name, I would like to be taken back to the original form with the information filled in.
How do I query the database and pass all the information to defaultNewInvest() so that the information that is currently in the database can be viewed and/or edited???
I have searched the web and can not find any examples of this. I have seen HTML::Template but did not know if that was the best was to proceed. If anything is not clear, please ask. I am desperate for a solution.
Thanks in advance. I am including the code for creating my form. Maybe that will help in figuring out what I am not understanding.
PS. I have not included all hte subroutines. I merely included the if-elsif-else structure so that one can see the flow. Thanks again.
#!c:/perl/bin/perl.exe -w use strict; use DBI; use CGI; use vars qw($CGI $DBH $dbsource $schema $user $psswd $DEBUG $cookie); ($dbsource, $schema, $user, $psswd) = ($ENV{DB_SOURCE}, $ENV{SCHEMA}, +$ENV{USER}, $ENV{PSSWD}); $CGI = new CGI; $DBH=DBI->connect($dbsource,$user,$psswd,{RaiseError =>1, AutoCommit = +>0}) || die "Database connection not made: $DBI::errstr"; if ( $CGI->param("saveNewInvestBtn") ) { insertNewInvestigator($CGI, $DBH); } elsif ( $CGI->param("peopleSearchBtn") ) { peopleSearchResults($CGI, $DBH); } elsif ($CGI->param("keywords") eq "newInvest" ) { defaultNewInvestigator($CGI); } else { mainPage($CGI); } sub defaultNewInvest { my $q = shift; print $q->header(); print $q->start_html(-title=>'Primary Investigator Information'); print $q->h1("Primary Investigator Information"); print $q->start_form(-action=>"investigator.pl", -method=>"post", +-name=>"form1", -onSubmit=>"return checkInvestForm();"); print$q->h3("Address Information"); print $q->table( {-border=>0}, $q->Tr([ $q->td( ["Salutation*:", $q->popup_menu(-name=>"inves +t_salutation", -values=>["Dr.", "Mr.", "Mrs.", "Ms."])." +Degree: ".$q->textfield(-name=>"invest_degree")]), $q->td( ["First Name*:", $q->textfield(-name=>"invest +_fname", -size=>40)] ), $q->td( ["Mid. Name:", $q->textfield(-name=>"invest_m +name", -size=>40)]), $q->td( ["Last Name*:", $q->textfield(-name=>"invest_ +lname", -size=>40)] ), $q->td( ["Title:", $q->textfield(-name=>"invest_title +", -size=>40)]) ]) ); print $q->submit( -name=>"saveNewInvestBtn", -value=>"Save", class +=>"buttonstyle" ); print $q->end_form(); print $q->end_html(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Populating a form with data from a DB
by sandfly (Beadle) on Sep 08, 2004 at 22:38 UTC | |
|
Re: Populating a form with data from a DB
by joecamel (Hermit) on Sep 08, 2004 at 22:18 UTC | |
|
Re: Populating a form with data from a DB
by cLive ;-) (Prior) on Sep 09, 2004 at 09:28 UTC | |
|
Re: Populating a form with data from a DB
by Anonymous Monk on Sep 09, 2004 at 18:49 UTC |