Data logging

They have: 5 posts

Joined: Apr 2000

I need to create a DB and web page that my internal users post data onto which is then logged to a db.

Any suggestions on how to do this please?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

JW,

First you should decide what platform you want to use/are familiar with. Some popular ones are ASP,PHP, and Cold Fusion. Then you should decide which db platform you want to use, Access, mySQL, SQL7, etc.

Once you've decided that, the routine for saving data from a form into a db is pretty universal. You simply take the values from the form and insert them into your db.

I'll give you a quick example using ASP & SQL7.

Here's our form.htm

<HTML>
<HEAD>
<TITLE>Form Example</TITLE>
</HEAD>
<BODY>
<form method=post action=save_info.asp>
<p>Name: <input type=text name=txtName></p><br>
<p>Age: <input type=text name=txtAge></p>
</BODY>
</HTML>

Ok, here's the form handler save_info.asp, you could make the form and the form handler the same page using ASP but I've split them up to keep it simple:

<% SaveName = Trim(Request.Form("txtName")
SaveAge = Trim(Request.Form("txtAge")
'A simple check for blank entries
If SaveName <> "" Then
If SaveAge <> "" Then
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=YourDSN;UID=YourID;PWD=YourPW"

Set RSUpdate = Server.CreateObject("ADODB.Recordset")

RSUpdate.ActiveConnection = Conn
RSUpdate.CursorType = 3 'adOpenKeyset
RSUpdate.LockType = 2 'adLockOptimistic
RSUpdate.Source = "YourTable"
RSUpdate.Open
RSUpdate.AddNew

RSUpdate.Fields("Name") = SaveName
RSUpdate.Fields("Age") = SaveAge

RSUpdate.Update
RSUpdate.MoveFirst
RSUpdate.Close

Set RSUpdate = nothing
Conn.Close
Set Conn = nothing
Response.Write "Done!"
Else
Response.Write "No Age!"
End If
Else
Response.Write "No Name!"
End If
%>

That's just a very basic example of saving new records.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 89 posts

Joined: Sep 1999

Hehe, I had almost forgotten how tedious ASP could be. The following Coldfusion lines accomplish the same task

<cfquery name="whatever" datasource="YourDB">
INSERT INTO YourTable (Name, Age)
VALUES ('#Form.txtName#', '#Form.txtAge#')
</cfquery>

Validation would be coded at the source like so:

<CFINPUT type=text name=txtName Required="yes" Message="You must enter your name!">

Anyway, I used to use ASP and it is really good for some things, but I am glad my job moved me onto CF.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.