form inout to database cgi code example

Example 1: form inout to database cgi

<FORM ACTION="/cgi-bin/program.pl" METHOD="POST">

Example 2: form inout to database cgi

<html>
<head>
<title>Add New Contact</title>
</head>
<body>
<div align=center>
Contact Database<br><br>
Add New Contact<br><br>
</div>

<form name="addrec" method="post" action="insertrec.pl"><br>
    Firstname<input name="firstname" type="text">
    Middle Initial<input name="middle" type="text" size="3">
    Last Name<input name="lastname" type="text" size="20">
    Address<input name="street" type="text" size="40">
    Town<input name="town" type="text" size="15">
    Zip<input name="postcode" type="text" size="15">
    Phone<input name="phone" type="text" size="10">
    e-mail<input name="email" type="text" size="20">
    Comments<textarea name=comments rows=4 cols=50></textarea>
    <input type="button" name="addit" value="Add Contact"></td>
    <td><input type="reset" name="reset" value="Clear Form"></td>
</body>

</html>

//File: insertrec.pl
#!c:/perl/bin

use Win32::OLE;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
use CGI ':standard';

print header();

$firstname = param("firstname");
$lastname  = param("lastname");
$middle    = param("middle");
$street    = param("street");
$town      = param("town");
$postcode  = param("postcode");
$phone     = param("phone");
$email     = param("email");
$comments  = param("comments");

$table  = "contact_table";

$conn = Win32::OLE->new("ADODB.Connection");
$rs   = Win32::OLE->new("ADODB.Recordset");

$sql = "INSERT INTO $table (firstname, middle, lastname, street, town,postcode, telephone, email, comments)
        VALUES ('$firstname', '$middle', '$lastname', '$street', '$town','$postcode', '$phone', '$email', '$comments')";

$conn->Open("contact");
$conn->Execute($sql);

print "<br>Contacts Database<br>";
print "Record Added!<br>";
print "<a href=/addcontact.htm>Add Another Contact?</a><br><br>";
print "<a href=/home.htm>Home</a><br><br>";

$rs->Close;
$conn->Close;