This is the function that performs the parsing routine that splits out your name value pairs, creating an
associative array. This is a very handy function, feel free to use it with any CGI application you create.
This work is already done for you in the CGI module that is available from CPAN.
print "Content-Type: text/html\n\n";
print "<html><head><title>Record Added</title></head>";
print "<body>The Vendor has been added</body>";
print "</html>";
exit;
The final segment of code sends a response back to the browser. In it, you tell the user that the vendor
has been added. You can get very creative here. What you are doing in this step is passing a Web page
back to the browser. See Figure 14.2 for the result. Whatever you can do in a Web page, you can do
here. JavaScript, DHTML, and Flash animations are some examples. You are not limited because you
are embedding the HTML in a Perl script. You can be as creative as you want to be. There is one point
to mention—the first line in the code segment is mandatory. Your page will not be displayed if you do
not include it exactly as it appears. The two new lines are required for the content to be displayed in the
browser.
Figure 14.2 Sending confirmation back to the browser.
That's it. That's all you need to do to include database access with your Web pages.
Take a look at the CGI process one more time. A user fills a form or clicks a link that passes values
along with a request to a Perl Script. The script processes the values that were passed. It also performs
any database interactions and then sends a response back to the browser in the form of HTML.
Summary
Today, you learned the basics of the Perl Database Interface as it applies to MySQL. You have just touched
the tip of the iceberg. There is a lot you can do with Perl and MySQL. You can use Perl to help automate
MySQL administrative tasks, as well as help perform duties, such as reporting and maintaining your data.
The sky's the limit.
You also learned about the three objects that Perl gives you to help accomplish your database interface.
They are the DBI object, the database handle, and the statement handle. You learned how these
objects interact to provide you with a powerful and flexible interface for your database.
Another thing you learned today was how to create simple Perl CGI programs to accomplish
Web/database integration. You saw how you could use the DBI object to perform these tasks.
There is a whole world to discover when it comes to Perl/CGI/Database programming. Only the basics
were touched on today. If you would like to pursue this type of programming even more, Sams
Publishing offers a large selection of books to get you on your way, such as Sams Teach Yourself Perl
in 21 Days, by Laura Lemay or Sams Teach Yourself CGI in 24 Hours, by Rafe Colburn.