Results 1 to 7 of 7

Thread: Getting Data from html to cgi/perl

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    6

    Angry 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

  2. #2
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    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.
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    6

    Angry 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:
    1. #!/usr/local/bin/perl
    2. print "Content-type:text/html\n\n";
    3. print "<HTML>\n";
    4. print "<HEAD><TITLE>EnZYMES LIST</TITLE></HEAD> \n";
    5. print "<BODY>\n";
    6. print "<H1> ENZYMES WHICH RESTRICT YOUR SEQUENCE ARE:- </H1>\n";
    7. use AnyDBM_File;
    8. open(SFILE, 'c:\enzymes.dat') || die "\n Cant open enzymes.dat $!\n";
    9. dbmopen(%string,"list",0666);
    10.  
    11. while(<SFILE>) {
    12. chop;
    13. ($name,@site)=split(' ',$_);
    14.  
    15. $string{$name}=join(' ',@site);
    16.  
    17. }
    18. dbmclose(%string);
    19. close(SFILE);
    20. dbmopen(%string,"list",0666);
    21. $temp=$ENV('QUERY_STRING');
    22. chop $temp;
    23. while (($name,$site)=each(%string))
    24. {
    25.   if($temp=~m/$site/i)
    26.     {
    27.      $i++;
    28.     print "$i. $name \n";
    29.  
    30.     }
    31.  }
    32. print "\n $i enzymes found.\n";
    33. dbmclose(%string);
    34.  
    35. print "</BODY>", "</HTML>", "\n";
    36. exit(0);

    Thank you
    Last edited by Haymanti; Jul 28th, 2005 at 11:08 PM.

  4. #4
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    6

    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.

  6. #6
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    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?

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    6

    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
  •  



Click Here to Expand Forum to Full Width