Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1

foreach $i (0 .. $#fval){


($name,$val)=split (/=/,$fval[$i],2);


$val=~tr/+/ /;


$val=~ s/%(..)/pack("c",hex($1))/ge;


$name=~tr/+/ /;


$name=~ s/%(..)/pack("c",hex($1))/ge;


if (!defined($field{$name})) {


$field{$name}=$val;


}


else {


$field{$name} .= ",$val";


}

}

}

return 1;


}


This code does some neat things. First, it validates the entries to make sure that they are not blank. If
they are, the PrintError subroutine is called. This routine regenerates the Login.html page with
the error message printed at the top. The next bit of code takes the username and password and tries to
connect to the database. If everything checks out, the $Username and $Password variables are
passed on in the hidden input tags, and the PostAd.html page is created (see Figure 21.5). If a
connection is not made, the PrintError subroutine is called. This is a nice little trick to help create a
secure environment for your database and provide as little annoyance as the user.
Free download pdf