Part 1
Part 2
Part 3
Part 4 Feedback Privacy

Data Out

You may want to add a search capability, so the visitors can get only the records matching a given criteria. To do this, you will need a search form. Again, I will skip all the default HTML which has to go into a HTML document, and also all the formatting and layout.

1. <FORM ACTION="cgi_bin/lastname.idc" METHOD="POST" NAME="Search Form">
2. <P>LastName: <INPUT TYPE="TEXT" SIZE="20" NAME="LName">
3. <INPUT TYPE="SUBMIT" NAME="SubmitIt" VALUE="Go"> </P>
4. </FORM>

Line 1 defines the action for the submit button. In this case, it will execute the cgi_bin/lastname.idc. Line 2 creates a text box named LName, and line 3 creates the submit button with the label "Go".

Now, you'll need a IDC file called lastname.idc, and it should look like this:

1. Datasource: Contacts
2. Template: ../template.htx
3. SQLStatement: SELECT DISTINCTROW LastName, FirstName, E-Mail FROM Addresses WHERE (((LastName) LIKE '%LName%')) ORDER BY FirstName;

Lines 1 and 2 are the same as before. You may change the template in line two, that's entirely up to you. In line three, there's been some changes. A WHERE clause have been added to limit the output to matching records. In this case, LastName must exactly match what the user typed in the LName text box.

If you want to use a wildcard search, you will have to re-write the SQLStatement a little bit:

3. SQLStatements: SELECT DISTINCTROW LastName, FirstName, E-Mail from Addresses WHERE (((LastName) LIKE '%%%LName%%%')) ORDER BY LastName, FirstName;

Here, LName have been padded with two extra percent signs. This is the substitute for the * wildcard character in Access. The same SQL in Access would be:
LastName LIKE '*LName*'

This has also been a very simple example. With more complex relational databases, you'll end up using different joins, multiple clauses etc etc. The good news is that you can practically paste the SQL statement from Access into notepad, and with a few minor changes, you'll have a working IDC file.

Data in

You can also use web-pages to add data to your database. Might not be a good idea to add records to your contacts database on the web, but since I've chosen to use a Contacts database, I'm going to do it anyway.

First, you'll need an input form.

1. <FORM ACTION="cgi_bin/addto.idc" METHOD="POST" NAME="Add Form"
2. <P>
3. First Name : <INPUT TYPE="TEXT" SIZE="20" NAME="FName"> <BR>
4. Last Name: <INPUT TYPE="TEXT" SIZE="20" NAME="LName"> <BR>
5. E-Mail: <INPUT TYPE="TEXT" SIZE="40" NAME="Email"> <BR>
6. <INPUT TYPE="SUBMIT" NAME="SubmitIt" VALUE="Go" </P>
7. </FORM>

Here we have a form with 3 text boxes for input and a submit box. Line 1 defines the action of the submit button in line 6. When the user clicks on the submit button, the addto.idc file will be executed, and the information added to the database. Well, as soon as we have written the IDC file, that is...

1. Datasource: Contacts
2. Template: ../thanks.htx
3. SQLStatement: INSERT INTO Addresses (LastName, FirstName, E-Mail) VALUES ('%FName%', '%LName%', '%Email%')

There you go. The information will now be added to your database. However, there's no checking for duplicates here, nor any validation of data. If someone clicks the submit button will all blank fields, that's what you're going to get in your database. How to do that, you'll have to figure out...

© 2002 - 2005 Lars M. Hansen