|
-
Jun 23rd, 2005, 01:16 AM
#1
Thread Starter
New Member
Getting Data from html to cgi/perl
Hi,
I have a problem regarding cgi PERL programming.
How to take data from a HTML form text area and then do string comparison of the form data with the PERL DBM file data and then print the result on a new HTML page obtained through the search from the DBM file.
Thank you
-
Jun 23rd, 2005, 09:20 AM
#2
Fanatic Member
Re: Getting Data from html to cgi/perl
I dont know much about using perl with data bases, but for what you are looking for this link might help:
http://www.scit.wlv.ac.uk/~jphb/perl...dbmfilter.html
if you want to get the data from the form of the web page, use somthing like this:
Code:
if($POST['name_of_entry1'] == 'whatever'){
#do somthing
}
if($POST['name_of_entry2'] == 'somthing else from database'){
#do another thing
}
----
if you want a real life working example of getting data from a web page, run this:
Code:
#!usr/bin/perl
print "Content-type: text/html\n\n";
if($POST['button'] != ''){
print "<html>\n<head></head>\n<body>\nText Box data was: $POST['text1']<br />\n</body></html>";
}else{
print "<html>
<head>
</head>
<body>
<form method="POST" action="$env{'SCRIPT_FILENAME'}">
<input type="text" name="text" size="20"><input type="submit" value="Submit" name="button">
</form>
</body>
</html>";
}
1;
Last edited by ALL; Jun 23rd, 2005 at 09:38 AM.
-
Jul 27th, 2005, 08:25 AM
#3
Thread Starter
New Member
Re: Getting Data from html to cgi/perl
Hi,
I have a problem regarding cgi PERL programming.
How to take data from a HTML form text area and then do string comparison of the form data with the PERL DBM file data and then print the result on a new HTML page obtained through the search from the DBM file. I am posting my code also, the problem is I want the code for working on IIS server , this code works perfectly on perl alone but when connected to cgi , the output is not displayed on html page and it is not working in a loop.
Kindly help!
The code is:-
VB Code:
#!/usr/local/bin/perl
print "Content-type:text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>EnZYMES LIST</TITLE></HEAD> \n";
print "<BODY>\n";
print "<H1> ENZYMES WHICH RESTRICT YOUR SEQUENCE ARE:- </H1>\n";
use AnyDBM_File;
open(SFILE, 'c:\enzymes.dat') || die "\n Cant open enzymes.dat $!\n";
dbmopen(%string,"list",0666);
while(<SFILE>) {
chop;
($name,@site)=split(' ',$_);
$string{$name}=join(' ',@site);
}
dbmclose(%string);
close(SFILE);
dbmopen(%string,"list",0666);
$temp=$ENV('QUERY_STRING');
chop $temp;
while (($name,$site)=each(%string))
{
if($temp=~m/$site/i)
{
$i++;
print "$i. $name \n";
}
}
print "\n $i enzymes found.\n";
dbmclose(%string);
print "</BODY>", "</HTML>", "\n";
exit(0);
Thank you
Last edited by Haymanti; Jul 28th, 2005 at 11:08 PM.
-
Jul 28th, 2005, 06:12 PM
#4
Fanatic Member
Re: Getting Data from html to cgi/perl
The Good Lord know's I ain't the sharpest perl guy around but where you are splitting a string into a variable and an array? You sure that works? i.e. "($name,@site)=split(' ',$_);"
One problem I did spot is that you are attempting to print the value of "$name",line 6 of your code, before you have assigned it a value at line 13.
If you "use strict;" you can then run "perl -c script_name" and it should list most problems in the code.
-
Jul 28th, 2005, 11:12 PM
#5
Thread Starter
New Member
Re: Getting Data from html to cgi/perl
the use strict thing is not working and i am not using it because the query string is to be entered by the user and it could be anything , moreover the perl database should remain dynamic...
the hashes you mentione works perfectly in perl...
Thanks for the mistake you pointed out i have correctsed that but stil the problem remains the same.
Kindly, reply if you can help in the code and thnaks for looking into it.
-
Jul 29th, 2005, 02:14 PM
#6
Fanatic Member
Re: Getting Data from html to cgi/perl
Ok, I see now that the spilt I question actually returns more than 2 items, the first is assigned to "name" and all of the remainders get placed in "site"..my bad (guess I was kinda dozing there..lol)
There are a couple of things I'm not sure I understand. 1) Are you saying that the user has control not only of the values in the fields but of the field names as well? and 2) Which loop are you experiencing problems with?
Perhaps you should try a "foreach" loop in place of the 2nd while loop you have - i.e.
Code:
foreach (keys %string) {
print "$_ = $string($_)\n";
}
should print each keyname and it's value..you could replace the print with your string matching?
-
Jul 29th, 2005, 03:30 PM
#7
Thread Starter
New Member
Re: Getting Data from html to cgi/perl
the name and site r in the perl dbm file.......they query_string is in user's hand
i will try foreach and let u know
the problem is in the second loop.
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|