Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl passing data between scripts without using query string
    primarykey
    data
    text
    <p>I'm new to Perl. New to programming. I've written a few CGI screens for a create, search, and view "agent". Create inserts records into database tables, search displays some details of the record, allowing a user to select which record they wish to work with and view pulls the record back out and displays them to the user based on the ID selected from search (well not yet it doesnt). </p> <p>On my search page, I've got the page displaying based on the search type and search keywords defined by the user. I'm looking to take the user to the "view agent" page based on their record selection from search.</p> <p>I was hoping to accomplish this by passing the record ID from the database table of the record selected by the user on the search screen. Is there is a way for me to reliably pass the ID selected between scripts (searchagent.pl to agent.pl) without using query string? This script is for internal use only and no private information comes into play.</p> <p>I did look around a little and saw global variables and package, but I wasn't so sure either of these was what I needed. </p> <p>Thanks in advance for the help. </p> <p>Edited to include some code:</p> <p>Grabs search type and search keywords from previous subroutine and runs an sql query based on that. Returns tabled output into a different subroutine displaying results. I have the weird multiple link thing going on in the table output because I've got some css styling making it seem like the entire row is highlighting when moused over.</p> <pre><code>sub GetResults { my $searchtype = $form{'radio'}; my $searchfor = $form{'searchby'}; my ($selectID, $selectname, $selectphone, $selectstate, $selectzip); given ($searchtype) { when('a.agentid') { $selectID = "CHECKED"; } when('a.name') { $selectname = "CHECKED"; } when('c.phonenumber') { $selectphone = "CHECKED"; } when('addy.state') { $selectstate = "CHECKED"; } when('addy.zipcode') { $selectzip = "CHECKED"; } default { $selectID = "", $selectname = "", $selectphone = "",$selectstate = "", $selectzip = ""; } } my $sth = $dbh-&gt;prepare("select a.AgentID, a.name, c.phonenumber, addy.state, addy.zipcode from agent a inner join entity e on entityid = agentid inner join contact c on contactid = billingcontactid inner join address addy on addressid = physicaladdressid where $searchtype like '%$searchfor%' order by $searchtype;") or die "prepare statement failed: $DBI::errstr\n"; $sth-&gt;execute; my ($table, $f1, $f2, $f3, $f4, $f5); while (($f1, $f2, $f3, $f4, $f5) = $sth-&gt;fetchrow_array) { $table .= "&lt;tr&gt;&lt;td align=center&gt;&lt;font size=\"4\" color=\"black\"&gt;&lt;a name=\"idagent\" href=\"agent.pl?agentid=$f1\"&gt;$f1&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;td align=center&gt;&lt;font size=\"4\" color=\"black\"&gt;&lt;a name=\"idagent\" href=\"agent.pl?agentid=$f1\"&gt;$f2&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;td align=center&gt;&lt;font size=\"4\" color=\"black\"&gt;&lt;a name=\"idagent\" href=\"agent.pl?agentid=$f1\"&gt;$f3&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;td align=center&gt;&lt;font size=\"4\" color=\"black\"&gt;&lt;a name=\"idagent\" href=\"agent.pl?agentid=$f1\"&gt;$f4&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;td align=center&gt;&lt;font size=\"4\" color=\"black\"&gt;&lt;a name=\"idagent\" href=\"agent.pl?agentid=$f1\"&gt;$f5&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;"; } $sth-&gt;finish; return ($table, $searchfor, $selectID, $selectname, $selectphone, $selectstate, $selectzip); } </code></pre> <p>When a record is selected I'm using query string to pass the ID of the record selected and run this subroutine and display the results in another subroutine. I'm doing using values of the array to print values into a text field and using some given statements to determine drop downs. <strong>That being said is there a faster way for me to determine state selection that using given and listing out all 50 states?</strong></p> <pre><code>sub GetAgent { my $sth = $dbh-&gt;prepare("select a.name, a.paidcommission, a.paidreferral, paddy.address1, paddy.address2, paddy.city, paddy.state, paddy.zipcode, maddy.address1, maddy.address2, maddy.city, maddy.state, maddy.zipcode, bc.name, bc.phonenumber, bc.phoneext, bc.phonenumber2, bc.phoneext2, bc.fax, bc.email, sc.name, sc.phonenumber, sc.phoneext, sc.phonenumber2, sc.phoneext2, sc.fax, sc.email from agent a inner join entity e on entityid = agentid inner join address paddy on paddy.addressid = physicaladdressid inner join address maddy on maddy.addressid = mailingaddressid inner join contact bc on bc.contactid = billingcontactid inner join contact sc on sc.contactid = salescontactid where a.agentid = $form{agentid};") or die "prepare statement failed: $DBI::errstr\n"; $sth-&gt;execute; my @agentval = $sth-&gt;fetchrow_array; $sth-&gt;finish; return (@agentval); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload