May 25, 2011

How to collect data from web visitors and save them in your database

It is very easy to make data collecting web application using the WhizBase. We will do it using only two WBSP files - one containing the form (form.htm) and the other that saves received data into the database (add.wbsp).

Database structure for subscribers.mdb
Table Mlist
FistName Text 50
LastName Text 50
Email    Text 50

File form.htm
<title>Subscribe to mailing list</title>
<form action="add.wbsp" method="POST">
<table border="1" cellspacing="0"" cellpadding="3" bordercolor="#000000" bgcolor="#FFFFFF" style="border-collapse:collapse;">
<tr><td valign="top"><strong>First Name</strong></td><td valign="top"><input type="text" name="WBF_FirstName" value=""></td></tr>
<tr><td valign="top"><strong>Last Name</strong></td><td valign="top"><input type="text" name="WBF_LastName" value=""></td></tr>
<tr><td valign="top"><strong>Email Address</strong></td><td valign="top"><input type="text" name="WBF_email" value=""></td></tr>


<input type='submit' value='Submit'> <input type='reset' value='Reset'>

File add.wbsp
<title>Thank you for subscribing</title>
Thank you for subscribing with us!<br>
Added data:<br>
$wbf[FirstName] $wbf[LastName], $wbf[email]

As you can see, first file is ordinary HTML file with form, text input fields and submit/reset buttons. Second file is a simple WhizBase program that instruct WhizBase to use the table mlist from database file subscribers.mdb, to add data received in WBF_ form fields and to display added data using $wbf function.

No comments: