hi all,
i've been trying, almost for the whole day, to submit the value of a variable in my perl script (eg, $sequence) to a subroutine in the same script when i click on a submit button. how can i do that? is there any other way execute a second perl script with a click of a button on the first one, submitting the same values of variables in first one????
your help would be greatly appreciated.
9 2184 numberwhun 3,509
Recognized Expert Moderator Specialist
hi all,
i've been trying, almost for the whole day, to submit the value of a variable in my perl script (eg, $sequence) to a subroutine in the same script when i click on a submit button. how can i do that? is there any other way execute a second perl script with a click of a button on the first one, submitting the same values of variables in first one????
your help would be greatly appreciated.
If we are to help you, we will definitely need to see the code that you have been working with. Please be sure and surround the code with the proper [code] [/code] tags when posting it.
Regards,
Jeff
Thanks for reminding me of the CODE tags, Jeff. I always forget about that. Sorry, if I've caused you trouble with that in the past.
OK, so here is what I want my code to do. The following code which is a part of my perl script displays the info as an html table, and that part is fine. -
print '<TABLE border="1" cellspacing="0" cellpadding="3" width="80%">' . "\n";
-
print "<tr><th width='15%'>Entry one</th><td>" . $one . "</td></tr>\n";
-
print "<tr><th>Entry two</th><td>" . $two . "</td></tr>\n";
-
print "<tr><th>Entry three</th><td>" . $three . "</td></tr>\n";
-
print "</TABLE>\n";
-
print "<br>";
-
-
print '<form name="myForm" method="post">'."\n";
-
print '<input type="hidden" name="insert1" value="$one">'."\n";
-
print '<input type="hidden" name="insert2" value="$two">'."\n";
-
print '<input type="hidden" name="insert3" value="$three">'."\n";
-
print '<input type="submit" name="submit_myForm" value="Submit">'."\n";
-
print '</form>'."\n";
-
But, now when I click on the Submit button, I want the following part of the script to be executed. -
my $dbh = DBI->connect ("DBI:mysql:database:123.456.789.1","user","pass") or die "Error: $DBI::errstr\n";
-
my $sql = "INSERT INTO protein (first, second, third) VALUES ('$one', '$two', '$three')";
-
my $in = $dbh->prepare($sql);
-
$in->execute;
-
How can I do that? I know it sounds easy, and may be it is, but I am so dump that I can't figure it out. Please, help.
Thanks a lot.
eWish 971
Recognized Expert Contributor
Assuming that you are using the CGI module. You can do it like so. - my $q = CGI->new;
-
my $from_data_name = $q->param('field_name_here');
Then use it later in your script use that variable where you want. But there are some security issues here, When ever you allow the user to submit data you always need to check the data to make sure that it is what you are escpecting. - sub process_form (
-
-
my $not_valid = 0;
-
-
#Check the incoming data to make sure it is safe to use. If not display the form again.
-
unless ($q->param('field_name_here') =~ /^(?:([\w\s+\d\']+))$/) {
-
$not_valid = 1;
-
}
-
#Check to see if the form needs to be displayed again.
-
if ($not_valid) { &display_form(); }
-
else { &next_sub(); }
-
-
}
-
-
sub next_sub (
-
-
my ($value1, $value2, $value3) = @_;
-
-
my $insert = $dbh->prepare('INSERT INTO protein (first, second, third) VALUES (?,?,?);
-
my $insert->execute($value1,$value2,$value3);
-
-
#rest of code here......
-
-
)
Use placeholders for your data when inserting and selecting from the database. It is safer and will cause you less headaches later.
Kelicula 176
Recognized Expert New Member
Assuming that you are using the CGI module. You can do it like so. - my $q = CGI->new;
-
my $from_data_name = $q->param('field_name_here');
Then use it later in your script use that variable where you want. But there are some security issues here, When ever you allow the user to submit data you always need to check the data to make sure that it is what you are escpecting. - sub process_form (
-
-
my $not_valid = 0;
-
-
#Check the incoming data to make sure it is safe to use. If not display the form again.
-
unless ($q->param('field_name_here') =~ /^(?:([\w\s+\d\']+))$/) {
-
$not_valid = 1;
-
}
-
#Check to see if the form needs to be displayed again.
-
if ($not_valid) { &display_form(); }
-
else { &next_sub(); }
-
-
}
-
-
sub next_sub (
-
-
my ($value1, $value2, $value3) = @_;
-
-
my $insert = $dbh->prepare('INSERT INTO protein (first, second, third) VALUES (?,?,?);
-
my $insert->execute($value1,$value2,$value3);
-
-
#rest of code here......
-
-
)
Use placeholders for your data when inserting and selecting from the database. It is safer and will cause you less headaches later.
You can run anything you want after form submission by including a if(param()) clause.
When the page first loads, the param is "undefined" and will return false.
Once the form is submitted it will return true, and the code will be executed.
Also a very good way to check that input submitted by users is safe is by using the "-T" switch. "taint mode". It's not fail safe, but it's easy, and a lot better than nothing. The main problem is that you don't have as much control over what happens after an erroneous entry is made, for that reason eWish's code is useful. But just in general it's good for stopping bad entries, what happens next is ??....
example: -
#!/usr/bin/perl -T
-
-
use strict;
-
use CGI qw(:standard);
-
-
print header;
-
print start_html();
-
-
my $one = "hey";
-
my $two = "you";
-
my $three = "there";
-
-
-
print start_form(-enctype=>"application/x-www-form-urlencoded"),
-
textfield(-name=>'insert1', value=>$one),
-
textfield(-name=>'insert2', value=>$two),
-
hidden('insert3',$three), # if you want hidden, they default to name, value.
-
submit();
-
-
-
if(param()){
-
-
my $on = param('insert1'); # remember to grab values from param
-
my $tw = param('insert2');
-
my $th = param('insert3');
-
-
# It's not necessary to create unique scalars, but I play it safe.
-
-
#do whatever with $on, $tw and $th...
-
# they will contain what the user or script inserted into
-
# the form inputs named accordingly. (see the param calls)
-
-
}
-
You see, by not specifying, perl inserts the current %ENV{SCRIPT_NAM E} into the action value in the form tag. The script will call on itself to process the input.
This does work.
See HERE
PS- It's looks like you are need of a here document also.
Instead of repeating so many lines of
print
print
print
etc...
You can create an area where perl will interpret as a separate field.
Most symbols that need to be escaped are ignored by perl and can be used, like
%, and " , or -, and =.
example: -
print <<EOH;
-
-
you can write regular html code in here, without much consideration for perl constraints. Perl variables however, will be interpolated to their values.
-
-
EOH
-
It's very useful.
You can also assign it to a variable: -
my $stuff = <<EOF;
-
-
write stuff here...
-
-
-
EOF
-
Now all that stuff will be stored in $stuff.
Notice that there is NOT a semi-colon after the last identifier.
<<EOF;
than
EOF
Anyway have fun!!
eWish 971
Recognized Expert Contributor
PS- It's looks like you are need of a here document also.
Instead of repeating so many lines of
print
print
print
etc...
You can also use the qq operator. - print qq~
-
<table border="1" cellspacing="0" cellpadding="3" width="80%">
-
<tr>
-
<th width='15%'>Entry one</th>
-
<td>$one</td>
-
</tr>
-
<tr>
-
<th>Entry two</th>
-
<td>$two</td>
-
</tr>
-
<tr>
-
<th>Entry three</th>
-
<td>$three</td>
-
</tr>
-
</table>
-
<br>
-
<form name="myForm" method="post">
-
<input type="hidden" name="insert12" value="$one">
-
<input type="hidden" name="insert22" value="$two">
-
<input type="hidden" name="insert32" value="$three">
-
<input type="submit" name="submit_myForm2" value="Submit">
-
</form>
-
~;
But I like keeping my HMTL seperate from my code. To me it makes it cleaner. HTML::Template
Thanks a lot eWish and Kelicula. I'm still a bit unsure as to how I should write it all. My initial input comes from an html form, which submits it to the perl script that I mentioned earlier. Here is how it actually looks like: -
#!/usr/bin/perl -w
-
use strict;
-
use CGI;
-
use Bio::DB::SwissProt;
-
my $database = new Bio::DB::SwissProt;
-
my $cgi = new CGI;
-
print $cgi->header() .
-
$cgi->start_html(-title => 'Results', -bgcolor => '#6699CC').
-
$cgi->h1('Results from the DB') . "\n";
-
-
my @params = $cgi->param();
-
foreach my $parameter (@params) {
-
my $value=$cgi->param($parameter);
-
my @values=split(/\s+/,$value);
-
foreach my $acc (@values){
-
chomp($acc);
-
-
# gets info. using the $acc with BioPerl module....
-
my $one = $seq->seq();
-
#and so on ...
-
-
#the variables are then displayed as follows
-
print '<TABLE border="1" cellspacing="0" cellpadding="3" width="80%">' . "\n";
-
print "<tr><th width='15%'>Entry one</th><td>" . $one . "</td></tr>\n";
-
print "<tr><th>Entry two</th><td>" . $two . "</td></tr>\n";
-
print "<tr><th>Entry three</th><td>" . $three . "</td></tr>\n";
-
print "</TABLE>\n";
-
print "<br>";
-
print '<form name="myForm" method="post">'."\n";
-
print '<input type="hidden" name="insert1" value="$one">'."\n";
-
print '<input type="hidden" name="insert2" value="$two">'."\n";
-
print '<input type="hidden" name="insert3" value="$three">'."\n";
-
print '<input type="submit" name="submit_myForm" value="Submit">'."\n";
-
print '</form>'."\n";
-
Now with the the submit I wanted to insert the same displayed variables that is in the table ($one, $two and $three) to the MySQL db.
Cheers!!!
KevinADC 4,059
Recognized Expert Specialist
regardless of other problems you are having, this will not work: - print '<input type="hidden" name="insert1" value="$one">'."\n";
You have a scalar inside a single-quoted string construct: $one.
$one will not be expanded, it will be treated as the literal string $one.
You have to use a double-quoted string or a quote operator that interpolates scalars and arrays: - print "this is \"$foo\"";
-
print qq{this is "$foo"};
-
qq escapes the double-quotes for you making it very convenient to use. And if you use paired brackets as the delimiters, like {} or (), the qq operator keeps track of them so you don't have to escape them if you use them in the string: - $foo = 'a test';
-
print qq{this {is} "$foo"};
-
but if you use a symbol, like '~' or '!' as the delimiter you do have to escape it: - $foo = 'a test';
-
print qq~this \~is\~ "$foo"~;
-
hi KevinADC,
you were absolutely correct. i was overlooking the "single-quoted" thing. i think it should work now. let's see.
thanks a lot.
cheers!!!
it works fine now. thanks to all you guys.
^ ^*
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tracer |
last post by:
I have a variable named blnAnswer that is a flag in a subprocedure called ValidateEntries() set to true and tripped to false if something fails. When the variable comes out of the subprocedure and everything has passed it is true, but when it gets passed to the calc function it turns to false on the DimblnAnswer as Boolean = ValidateEntries() although the subprocedure is true. We bypassed the assignment and ran the code with just the...
|
by: Blaxer |
last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be...
function Calculate_Something(ByVal multiplyer as integer, ByVal variable as ___?)
variable = 5 * multiplyer
end function
What I would like this function to do is take the name of the incoming variable and assign a calculated value to it.
Any help would be greatly appreciated, TIA!!
|
by: Richard Hollenbeck |
last post by:
I've marked the line in this subroutine where I've been getting this error.
It may be something stupid but I've been staring at this error trying to fix
it for over an hour. I'm pretty sure the table and field names and controls
are all named correctly, and the control referred to in the errant code is
open, and it has data in it.
Private Sub cmdAddIngredientToRecipe_Click()
' Get RecipeID for future action query
Dim recipeID As Long
|
by: Tom_Slycke |
last post by:
In a VB.Net class and have pointed out a discrepancy to my teacher. Can
anyone here answer this?
Very simple program used to demonstrate the "ByRef" parameter passing.
If the ByRef truly refers to the variable location, I would have expected
the textbox1.text display to update right when the value change when NAME is
set to "Samantha" but the textbox1.text field does not reflect the change
until the subroutine completes.
|
by: gabba |
last post by:
Hi,
is it possible to call a subroutine (or a function) using variable name?
Sub a()
Response.write("sub a")
End sub
Sub b()
Response.write("sub b")
End sub
| |
by: shil |
last post by:
Hi all,
I am using javascript confirm() function to get user's confirmation
from codebehind after a condition is met. I don't want to attach the
function to the button on page load. When I submit the page, I want to
check some business rules, and based on the response from the database,
if the response is Yes, I need to display a confirmation alert to user.
When the user clicks ok,
then I should take an action, if not, exit out of the...
|
by: Looch |
last post by:
Something simple here (hopefully)...how can I append the text in a
text box to a hyperlink? For example, I enter the string 'Printer223'.
There is an Excel file with the same name that I want to open
(Printer223.xls). Basically http://localhost/printers/whatever I put
in the textbox.xls is what I'm after. Thanks.
|
by: zensunni |
last post by:
In a perfect world, I wouldn't have to do this, but I'm at the mercy of event scripting for a program.
there's an event that runs every so often that triggers an subroutine. I'd like to declare a variable in that subroutine, but not have to worry about it when an event triggers it again. If I just go:
Public variable As String
.. it will give an error. I need to check if the variable exists... can that actually be done? I've yet to see...
|
by: jim190 |
last post by:
I am relatively new to using VBA and am have been trying for two days to pass a user entered value to my report for filtering when opened. I have the following subroutine in the open event of my report:
Private Sub Report_Open(Cancel As Integer)
'Prompts for business unit when run educational assistance reports.
Dim strBusUnitName As String
strBusUnitName = UCase(InputBox("Enter Business Unit or click OK for all.", "Business Unit",...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |