Creating A Small Address Book Application In Whizbase

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses.

I will use a MS Access DB (.mdb file), but you can apply this tutorial for any DB you want, there is no significant difference, and the concept is the same.

We will make one default page which will show us all the records sorted alphabetically, then two files for update, one for delete and two for addition.

Creating the DB
I will not go through the SQL or the Access file creation, I will just describe what we need in the DB. We will need one table named contacts. It will have the following fields:

Id as integer(9) autoincreament primary key
Firstname as char(255)
Lastname as char(255)
Tel as char(255)
InsertionDate as DateTime

Whatever DB type you use, you will need these fields, so create the table and lets begin. I have created my contacts.mdb access DB file.

General file «default.wbsp»
This file will connect to the DB and select all the contacts sorted alphabetically by first name:

[FormFields]
WB_BaseName=contacts.mdb
WB_Command=Q
WB_RcdSet=contacts
WB_maxrec=20
WB_Order=Firstname
<!–WB_BeginTemplate–>
<html>
<head><title>Address Book</title></head>
<body>
<h1>Address Book</h1>
<table width=’80%’ border=’0′ cellpadding=’5′ cellspacing=’0′>
<tr><th>ID</th><th>First Name</th><th>Last Name</th><th>Telephone</th><th>Insert Date</th><th colspan=’2′>Action</th></tr>
<!–WB_BeginDetail–>
<tr><td>$wbf[id]</td><td>$wbf[Firstname]</td><td>$wbf[Lastname]</td><td>$wbf[Tel]</td><td>$wbf[InsertionDate]</td><td><a rel=”nofollow” href=’edit.wbsp?wbf_id=$wbf[id]‘>Edit</a> <a rel=”nofollow” href=’delete.wbsp?wbf_id=$wbf[id]‘>Delete</td></td></tr>
<!–WB_EndDetail–>
</table>
<a rel=”nofollow” href=’add.htm’>Add Contact</a>
</body>
</html>







In our first file we connect to the DB file contacts.mdb, which is located in the same folder as default.wbsp. In WhizBase we give instructions for DB connection at the beginning, so we first make [FormFields] section which is the start of the file header. We specify some parameters, WB_BaseName is the path of the DB, WB_Command will be Q as for Query. WB_maxrec will be 20 records, we want our address book to paginate the records in 20 rows each page. And WB_Order will be Firstname, because we want to sort the report alphabetically by Firstname.

<!–WB_BeginTemplate–> will mark the end of the file header. We now make the design of our address book. <!–WB_BeginDetail–> and <!–WB_EndDetail–> are used to loop through the query results. WhizBase brings you the data automatically, so you do not need to assign any variables or arrays. You need just to put the data placeholders in the code.

$wbf[fieldname] is the placeholder, as the system loops through the query result, for each row we take the value of the field name we want to show, in our case we are showing the id, firstname, lastname, tel and insertiondate.

We made three links, one for edit, another two for delete and add commands. Take a look at the edit and delete links, you will see that we are giving a wbf_id parameter. We will need that later.

Adding records Form

For more information email me at: NurAzije [at] Gmail [dot] comOr visit WhizBase official site at www.whizbase.comNurAzije is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects.
Article Source