Database Reference
In-Depth Information
if ( $s )
{
++ $found ;
print p ( "You entered the abbreviation: " . escapeHTML ( $keyword ));
print p ( "The corresponding state name is : " . escapeHTML ( $s ));
}
$s = $dbh -> selectrow_array ( "SELECT abbrev FROM states WHERE name = ?" ,
undef , $keyword );
if ( $s )
{
++ $found ;
print p ( "You entered the state name: " . escapeHTML ( $keyword ));
print p ( "The corresponding abbreviation is : " . escapeHTML ( $s ));
}
if ( ! $found )
{
print p ( "You entered the keyword: " . escapeHTML ( $keyword ));
print p ( "No match was found." );
}
$dbh -> disconnect ();
}
print p ( qq{
Enter a state name into the form and select Search, and I will
show you the corresponding abbreviation. Or enter an abbreviation
and I will show you the full name.
} );
print start_form ( - action => url ()),
"State: " ,
textfield ( - name => "keyword" , - size => 20 ),
br (),
submit ( - name => "choice" , - value => "Search" ),
end_form ();
print end_html ();
The script first checks whether a keyword parameter is present. If so, it executes the
statements that look for a match to the parameter value in the states table and displays
the results. Then it presents the form so that the user can enter a new search.
When you try the script, you'll notice that the value of the keyword field carries over
from one invocation to the next. That's due to CGI.pm's behavior of initializing form
fields with values from the script environment. If you don't like this behavior, defeat it
and make the field come up blank each time by supplying an empty value explicitly and
an override parameter in the textfield() call:
print textfield ( - name => "keyword" ,
- value => "" ,
- override => 1 ,
- size => 20 );
Search WWH ::




Custom Search