skip to Main Content

Everyone, how are you there?

I want to send a value from a PHP page by Form Action to a CGI script written in Perl. The method is either POST or GET, it doesn’t matter. I want to do it as simplest as possible. Is there any way without using CGI module? Or one must use CGI module?

Here is my trial without using CGI module. Please give me comments or feedback to help me around. Thanks, thanks, everyone.

 <?php
 $musician_fn = $_POST[‘musician_fn’];

 echo <<<END
 <form action=“URL_PATH/cgi_01.pl method=“POST”>
 <select name=“musician_fn”>
 <option value=“name1”> Name1 </option>
 <option value=“name2”> Name2 </option>
 …
 </select>
 <input type=“submit” Value=“Go”>
 </form>

 END;
 ?>

Now, CGI in Perl.

 #! /use/bin/perl -w

 $musician_fn = $FORM{musician_fn};

 print “$musician_fn”;
 

Unfortunately, this way doesn’t work.

Another CGI by using CGI module, which I used to use.

 #! /use/bin/Perl -w

 Use CGI qw(:standard);

 $musician_fn = param(“musician_fn”);

 print “$musian_fn”;

This code worked before in Perl 5.8.8, but not in Perl 5.36.0. How should I fix? Thanks,thanks,everyone.

Any idea to fix the bug.

2

Answers


  1. Chosen as BEST ANSWER

    I got it by the way of using CGI module in Perl. CGI module was loaded by my administrator by cpan according to him.

    HERE is PHP part

    <php?
    echo <<<END
    <form action="http://110.3.33.130/cgi-bin/cgi61_us15.pl">
    <table width="500" cellspacing="1" cellpadding="2">
    
    <tr>
    <td width="200"><b>BY NAME alternative </b></td>
    <td>
    <select name="musician_fn">
    <option selected> Scroll down please.
    <option value="bangles">                                  Bangles, The                                                                        </option>
    <option value="10_000_maniacs">                           10,000 Maniacs                                                                      </option>
    <option value="112_group">                                112                                                                                 </option>
    <option value="2pac">                                     2Pac                                                                                </option>
    <option value="2_unlimited">                              2 Unlimited                                                                         </option>
     </select>
     <input type="submit" value="Go">
     </form>
    </td></tr>
    </table>
    END;
    ?>
    

    ======================================

    And here is the Perl part.

    #! /usr/bin/perl -w
    use CGI qw(:standard); 
    $musician_fn = param("musician_fn");    
    

    This way did the good capture of a variable from PHP to Perl_CGI.

    ======================================

    Here is on my way to turtle code, at fist PHP code, named turtle_cgi.php

    <html>
    
    <a href="http://my_serverIP/cgi-bin/turtle_cgi.pl"> link </a>
    
    LET me see.
    
    </html>
    

    ================= And here is turcle_cgi.pl (on my way to turtle codes)

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use CGI;
    
    my $q = CGI->new;
    print $q->header();
    print "OK";
    

    It worked by calling from WEB-caster.


  2. There seem to be syntax errors in both your php and perl.
    Note the quotes are plain quotes.
    many will say not to use CGI but going with what you asked:
    These two files can talk to each other:

    
         <?php
         $musician_fn = $_POST[‘musician_fn’];
        
         echo <<<END
         <form action="getPhp.pl" method="POST">
         <select name="musician_fn">
         <option value="Miles Davis"> Miles Davis </option>
         <option value="Prince"> Prince </option>
         </select>
         <button type="submit"> Go </button>
         </form>
        
         END;
         ?> 
    
    

    Note I call this file getPhp.pl

        #! /usr/bin/env perl
        use warnings;
        use strict;
        
        use CGI::Carp; # send errors to the browser, not to the logfile
        use CGI;
        
        my $cgi = CGI->new(); # create new CGI object
        
        my $musian_fn = $cgi->param('musician_fn');
        
        print $cgi->header('text/html');
        
        if ($musian_fn){
            print "Musician: $musian_fn";
        }
        else {
            print "Musician not found";
        }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search