Slide 5.3: Entering book information
Slide 5.5: Entering book information (cont.)
Home

Entering Book Information (Cont.)


Once the button Submit or Help of the top part of the previous interface is clicked, the CGI Perl script below will be activated. It performs the following three tasks:
~wenchen/public_html/cgi-bin/351/week5/EnterBooks1.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI; 
$query = new CGI;
$act   = $query->param( 'act' );
 
if ( $act eq "Enter books" ) {
  # Retrieve web argument values. 
  $title    = $query->param( 'title' );
  # Remove leading and trailing spaces.
  $title    =~ s/^\s*(\S*)\s*$/$1/;
  # For security, remove some Unix metacharacters.
  $title    =~ s/;|>|>>|<|\*|\?|\&|\|//g;
  $ISBN     = $query->param( 'ISBN' );
  $ISBN     =~ s/^\s*(\S*)\s*$/$1/;
  $ISBN     =~ s/;|>|>>|<|\*|\?|\&|\|//g;
  $price    = $query->param( 'price' );
  $price    =~ s/^\s*(\S*)\s*$/$1/;
  $price    =~ s/;|>|>>|<|\*|\?|\&|\|//g;
  $quantity = $query->param( 'quantity' );
  $quantity =~ s/^\s*(\S*)\s*$/$1/;
  $quantity =~ s/;|>|>>|<|\*|\?|\&|\|//g;
  system( "./EnterBooks1 '$title' '$ISBN' '$price' '$quantity'" );
  system( "/bin/cat EnterBooks1.html" );
}
elsif ( $act eq "Help" ) {
  system( "/bin/cat Help.html" );
}
elsif ( $act eq "Home" ) {
  system( "/bin/cat FPDemo.html" );
}
else {
  print( "No such option: $act" );
}