(This article is about an easy database search for matching a string of text. Simple Database Search (number search) is about an easy database search for numbers within a range.)
An Easy Database Search Implementation
This demonstrates how easy it is to implement a database search for your web site visitors.
Searching to Match a String of Text
The example searches fields for a string of text submitted with a form.
The CGI script and form can be modified to do searches on
other fields and to do different comparisons for matches.
If you need a bit of help with modification,
click here to tell us about your project.
Just Three Installation Steps
The three steps are
Uploading the script and giving it correct permissions.
Creating and uploading the database.
Searching.
Step 1 — Uploading the script and giving it correct permissions
Upload this script into a directory that can run Perl CGI programs. It needs to be uploaded as ASCII/plain text and given 755 permissions. If the location of perl on your server is different than in the script below, the first line of the script needs to be changed.
Note: When you copy this script and paste it into your word processor for saving to your hard drive, the word processor needs to be a plain text word processor like NotePad or BBEdit. Word, FrontPage, and other WYSIWYG and rich text word processors and page makers can introduce script breaking formatting characters.
Step 2 — Creating and uploading the database
Create a tab-delimited plain text database file named "database.txt" and upload it to your server into the same directory the script is at.
database.txt has three fields, in this order:
The name of the item.
The URL to the web page describing the item.
The title or name of the item.
Any spreadsheet or database program that can export to tab-delimited plain text file can be used. Access and Excel are just two examples.
Step 3 — Searching
To do a search, a link with a URL like this can be used:
(Where "swift" is the text to search for.)
Or, a form like this can be used (note that it's method="GET":
Automatic error correction
The script will automatically remove any spaces from the search text and from the text in the database field. Thus, extra or missing spaces won't spoil the search.
The script will automatically search case-insensitive so capitalization errors won't spoil the search.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]