[AccessD] Using ASP to put a database on the web (Part 2)

Drew Wutka DWUTKA at Marlow.com
Fri Dec 7 18:15:49 CST 2007


Well, we built a simple page to display data from a database.  But
that's the simple method.  How much more difficult is it to allow people
to actually work with the data?

Not hard at all.  We've already built the classes (with the utility I
put a link up for). Let's change the default.asp page (the page we built
last email) to look like this: (Note, I think I goofed on my previous
email, the includes were all for dbconnect, instead of all three files,
like below)

<!-- #include virtual = "dbconnect.asp" -->
<!-- #include virtual = "person.asp" -->
<!-- #include virtual = "people.asp" -->
<html>
<head>
<title>AccessD Test Page</title>
</head>
<body>
<form name="AddNewPerson" method=post action="adduser.asp">
<table width="50%" border=1>
	<tr>
		<td width="30%" colspan=2><b>Commands</b></td>
		<td width="35%"><b>Last Name</b></td>
		<td width="35%"><b>First Name</b></td>
	</tr>
<%
dim i
dim pr
dim pl
set pr=New Person
set pl=New People
for i=1 to pl.PersonCount
	set pr=pl.PersonInfo(i)%>
	<tr>
		<td width="15%" align=center><a
href="edituser.asp?PersonID=<%=pr.ID%>">Edit</a></td>
		<td width="15%" align=center><a
href="deleteuser.asp?PersonID=<%=pr.ID%>">Delete</a></td>
		<td width="35%"><%=pr.LastName%></td>
		<td width="35%"><%=pr.FirstName%></td>
	</tr>
<%next%>
	<tr>
		<td width="30%" colspan=2 align=center><input
type=submit value="Add New"></td>
		<td width="35%"><input type=text size=30
name="FirstName"></td>
		<td width="35%"><input type=text size=30
name="LastName"></td>
	</tr>
<%
set pr=nothing
set pl=nothing
%>
</table>
</form>
</body>
</html>

Note that we now have the user information in an html table.  Looks
nicer that way.  Note, also, that the rows of the table are created
dynamically...this is called Conditional HTML.  Conditional HTML is when
you use a server side script (like ASP) to show, not show, or repeat
HTML.  In this case, we have the <tr></tr> flags and the rest in between
them within an 'For i=1 to x' 'next' clause.

Now that we have a new page, let's add the support files.  The 'Add New'
button is going to require an 'adduser.asp' page (the action property of
the form).

Adduser.asp:

<!-- #include virtual = "dbconnect.asp" -->
<!-- #include virtual = "person.asp" -->
<%
dim pr
set pr=new Person
pr.StorageOnly=False
pr.FirstName=request.form("FirstName")
pr.LastName=request.form("LastName")
pr.Save
'response.Write pr.FirstName & ", " & pr.LastName
set pr=nothing
response.Redirect "default.asp"
%>

Nice, simple and direct.  Let's add a deleteuser.asp to remove a user
from the table.

Deleteuser.asp:

<!-- #include virtual = "dbconnect.asp" -->
<!-- #include virtual = "people.asp" -->
<%
dim pl
set pl=new People
pl.DeletePerson request.QueryString("PersonID")
set pl=nothing
response.Redirect "default.asp"
%>

Note, that in adduser.asp, we don't include people.asp, and in
deleteuser.asp we don't include person.asp, because those classes just
aren't used in these short .asp files.

We'll go and create the edituser.asp page in the next part.

Drew




More information about the AccessD mailing list