Get form value with param : Form « CGI « Perl






Get form value with param

     

#!c:/ActivePerl/bin/perl.exe

use DBI;
use CGI qw(:standard);

print header, start_html(-title=>"Team Lookup",-BGCOLOR=>"#66ff33");
print start_form,"<font face='arial' size='+1'>Look up what name? ",textfield('name'),p;
print submit, end_form, hr;

if(param())  {
    $team = param('name');

    $dbh = DBI->connect("DBI:mysql:host=localhost;database=sample_db;user=root;password=") or print "Connection failed: ". $DBI::errstr;
    $sth=$dbh->prepare("SELECT name, salary, age FROM teams where name = ?");
    $sth->execute($team);
    if ($sth->rows == 0){
         print "Your team isn't in the table.<br>";
         exit;
    }
    print h2("Data for \u$team");
    while(($name,$salary,$age) = $sth->fetchrow_array()){
        print <<EOF;
            <table border="1">
               <tr>
                   <th>Name</th>
                   <th>Salary</th>
                   <th>Age</th>
               </tr>
               <tr>
                   <td>$name</td>
                   <td>$salary</td>
                   <td>$age</td>
               </tr>
            </table>
          EOF
          print end_html();
          $sth->finish();
          $dbh->disconnect();
    }
}

   
    
    
    
    
  








Related examples in the same category

1.Form Input Types
2.Demonstrates GET method with HTML form.
3.Demostrates POST method with HTML form.
4.Demonstrates use of CGI.pm with HTML form.
5.Create HTML form with CGI
6.Get form submitted value
7.Using param() function to get parameter
8.Using CGI function to check the parameter
9.Create a form and set the method and action
10.Create a form with submit button
11.Process form with regular expression: first name and last name
12.Process form with regular expression: date
13.Process form with regular expression: time
14.Generate the HTML form
15.Printing the Name Input Using the CGI Module
16.Generate and Process Forms
17.Form Mail
18.Form based table editing
19.Create a form with Perl code
20.Code to Accept Input with the CGI Module
21.Capitalize the first letter of each parameter using ucfirst
22.A Form-Based Example
23.Learn about the current CGI request
24.Read the data for a CGI GET request
25.Read the data passed to a script on the command line?
26.Decoding the Input Data
27.The POST Method
28.Verifying a username and a password
29.Sample Database Query
30.Writing a cookie to the client computer
31.Add a New Phone Number
32.Sessions - Preserving State
33.Separate the form and perl script
34.Add form data to database
35.Passing parameter to perl CGI code
36.EMail sending form
37.Guest book form
38.Data-Entry Forms in Web Pages
39.Using LI
40.Using the option select box
41.Reading text in textarea
42.Querying all the parameters