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

(singke) #1

if ($buf eq "") {


return 0 ;


}


else {


@fval=split(/&/,$buf);


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 script shows you how you can check the input values before inserting them into your database. It is
important to remember that if you want good data to come out, you need to put in good data. You are
also creating the users and giving them privileges in the MySQL database in this code. You can see that
this is accomplished with the GRANT statement. You also FLUSH the grant tables before you disconnect
from the server. This is done so that the user can log in immediately. You have seen everything in this
code before, with the exception of the error checking and adding users and privileges.
Free download pdf