CSVwrite

CSVwrite - Write to a database from a web form

Send information to a database from a form in a webpage. Very simple to set-up and customise with the look and feel of your own website. The data is stored as a CSV database. (CGI/Perl)

Requirements

Files you will need to download:

  • CSVwrite script
  • Webpage with a form (Or make your own)
  • CSV Database

Download Script & example files:

Things you have to do:

  • Download the script and make a few changes
  • Create a form on your webpage
  • Create database (or let CSVwrite do it!)
  • Upload the script, template and database.

Minimum Requirements:

  • A little experience in uploading and running CGI Perl scripts
  • Your own website with FTP access
  • Permission to run CGI scripts on your server
  • UNIX web hosting with the current version of Perl
Setting-up the script

You will need to make some small changes to customise the script to make it work on your website. Open and edit the script in notepad or notepad++

#!/usr/bin/perl (This is your 'path to perl')
##########################################################
my $base_file = 'database.csv'; (This is the PATH of your database)
my $HTML_thankyou = 'thankyou.htm'; (The URL to display after data has been submitted)
my $ID_autoincrement = 1; (To use the unique ID feature set this to 1 or 0 not to use the feature)
my $ID_autoincrement_name = "ID"; (Set this to the field name that has the unique ID)
##########################################################

Upload to your website and CHMOD 755 if in the public directory or 777 if hidden

Create your database

The database is a CSV database, CSV stands for 'character separated values' sometimes called a flatfile database. It is basically a text file and the character | serperates the data.

When you download the scripts a demo database is included, you can edit this online with CSVedit or on your computer with Excel. However the best way to create the database is when you run CSVwrite the first time as it will create the database for you, make sure you put some data in each field of the form.

If you do create your own, don't use any special characters or spaces in the field names. Keep them short as your browser can only send a limited number of characters to the database at any one time. Ensure they match your form fields exactly. The size limitations of your database are determined by your web hosting and the server specifications.

Example database: The first line is the heading and the rest the data. You can have as many field names as you like in the database. The field names must exacly match the fields in your form.

fieldname1|fieldname2|fieldname3|fieldname4
This is a text box|yes|1|Drop it A
This is a text box|Yes|2|Drop it B
This is a text box|Yes|3|Drop it C

Your database should be less than 1000 records and under 1MB run smoothly on most shared web servers.

Please do not use field names in your database used in the script or template. The following are used by the scripts and can not be used as field names: name, method, action, page, record, header, display, search.

Upload to your website and CHMOD 755 if in the public directory or 777 if hidden

Create the form on your website

CSVwrite will work with alomost any form on your website, you can have text fiels, dropdown fiels, tick boxes, or radio button. As many form fields as your server and browsers can handle, all customised to your needs.

The form action is the URL of your CSVwrite script, so each form will need to start:
<form method="POST" action="csvwrite.pl">

Your fields are in the middle, then end with:
<input type="submit" value="send">
</form>

Example Code: (Ensure the field names match your database headings. Don't use any special characters or spaces in the field names. Keep them short as your browser can only send a limited number of characters to the database at any one time.)

<form method="POST" action="csvwrite.pl">
Field 1: <input type="text" name="field1" size="40"><br>
Field 2: <input type="text" name="field2" size="40"><br>
Field 3: <input type="text" name="field3" size="40"><br>
Field 4: <input type="text" name="field4" size="40"><br>
Field 5: <input type="text" name="field5" size="40"><br>
<input type="submit" value="send">
</form>

Create the 'thank you' page

The 'Thank You' page has no special requirements.
You can use any page on your website or the internet!

Live demo

Working example:

Field 01:
Field 02:
Field 03:
Field 04:
Field 05:

Reset the demo database

The live demo allows you to post data, add, edit and delete fields or records.
Click to reset the demo database back to default.