Electric Type

Multimedia

About Us

News

Help

Intro to Perl for CGI

Page 11 — Just Like in the Movies

I'm into movies in a big way, and I have a lot to say on the topic. So for your CGI-learning enjoyment, I'm going to show you how to write a little movie-review search script. It's the perfect thing for the Web page of a true movie buff. But don't worry. If movies aren't your thing - say you're a death-metalhead like my buddy Dave - this script will work just peachy with a music collection; your spores, molds, and fungus collection; whatever).

Before we build the CGI, we have to name our input. One of the first things to learn about CGI scripting is that the more complicated you make something, the more likely it is that users won't understand how to use it. So let's keep things nice and simple and start with a form that accepts only one kind of input: the title of the movie. Let's name that form field "title" (see? no surprises). So on our Web page we have:

Please input the title of the movie you want to hear me rant about. It can be all caps, lowercase, whatever, but leave those "The"s right where they are. So if you're looking for "The 5,000 Fingers of Dr. T," type in the The before 5,000 Fingers of Dr. T. Or if it's "They Live" you seek, you can type in THEY LIVE, they live, They Live, and so on. Got it?

You'd do this with the following HTML:
<form action="/cgi-bin/crazymovie.cgi"><input type="text" length="20" name="title"><br><input type="submit" value="Search The Crazy Movie Megabase!"></form>
So now we look for the title in my "database." Again, to keep things nice and simple for this example, we won't play hardball with an actual database; there is no Oracle or SQL backend to this. We'll do everything with a "flat-file" database, which is just a collection of plain text files organized so that it's easy for the script to parse. Flat-files aren't good for really detailed searches or huge amounts of data, but they won't set you back several thousand dollars on hardware and software, either.

To pull info from our flat-file database, we have to know what the input from the database is going to look like so we can build the CGI around it. The format for each entry that I'll use will look exactly like this:

---- movie title ---- [lowercase]
movie title [how I want the user to see it, minus HTML tags]
movie description [no hard line breaks with \n, but <p> tags are OK]
So I've declared the formatting rules for my database, and both the data and the script must conform to these rules. They might seem a little anal, and I suppose they are. But believe me, the more rules you set before you input all your data, the easier things will be later. Scripting is a structured activity, and rules help define the structure.

Once I have my database ready to go I can make things happen with the user input I get from my form.

next page»


Dynamic HTML  

Frames  

HTML Basics  

Stylesheets  

Tables  

XML  

Javascript  

Database Connections  

Intro To Perl  

HTML 4.0  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.