Jim S. said:
I know i may be asking too much, but can you elaborate on that?
or give an example of one field ?
OK, but I'm just typing this cold. It's not debugged.
I'm going to assume that you have an Access database named
fpdb/mydatabase.mdb, with a table named mytable having these
three fields:
seqnum Autonumber, Primary Key
status Integer
visname String
This is ASP code:
<%
option explicit
%>
<html>
<body>
<%
dim seqnum
dim errmsg
dim strDb
dim conDb
dim rsDb
seqnum = request.form("seqnum") ' recycle sequence number (default)
strDb = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & server.mappath("fpdb/mydatabase.mdb")
Set conDb = Server.CreateObject("ADODB.Connection")
conDb.open strDb ' open connecttion to database
set rsDb = server.createobject("ADODB.Recordset")
if request.form("btnSub") = "" then ' btnSub is name of Submit button
InitializeForm
else
ProcessForm
end if
conDb.close
' ----------
Sub InitializeForm
dim sql
sql = "SELECT * FROM mytable where 1=0"
rsDb.Open sql, rsDb ' retrieve table structure but no records
rsDb.AddNew
rsDb("status") = 1 ' Set status to mean "not processed"
rsDb("visname") = ""
rsDb.Update
seqnum = rsDb("seqnum") ' get autonumber field from database
rsDb.close
End Sub
' ----------
Sub ProcessForm
dim sql
dim tmpseq
dim intseq
tmpseq = request.form("seqnum")
if not isnumeric(tmpseq) then
errmsg = "Invalid transaction sequence number."
exit sub
end if
intseq = cint(tempseq)
if intseq < 1 then
errmsg = "Invalid transaction sequence number."
exit sub
end if
sql = "SELECT * FROM mytable WHERE seqnum = " & intseq & " "
rsDb.Open sql, rsDb ' retrieve database record for assigned seq num
if rsDb.eof then
errmstg = "Transaction sequence number not found."
rsDb.close
exit sub
endif
if rsDb("Status") <> 1 then
errmsg = "Duplicate submission"
rsDb.Close
exit sub
end if
rsDb("status") = 2 ' Set status to mean "processed"
rsDb("visname") = request.form("txtName")
rsDb.Update
rsDb.Close
End Sub
' ----------
%>
<form method="POST">
<input type="hidden" name="seqnum" value="<%=seqnum%>">
<p><input type="text" name="txtName"
value="<%=request.form("txtName")%>"></p>
<p><input type="submit" name="btnSub" value="Submit"></p>
<p><%=errmsg%></p>
</form>
</body>
It has been suggested to make two file, 1 that is a just the form collecting
the data, and 2nd to post the data to the database and then redirect back to
the form, do u think that will work?
No. What to keep the visitor from pressing Submit again?
Jim Buyens
Microsoft FrontPage MVP
(e-mail address removed)
http://www.interlacken.com
Author of:
*------------------------------------------------------*
|\----------------------------------------------------/|
|| Microsoft Office FrontPage 2003 Inside Out ||
|| Microsoft FrontPage Version 2002 Inside Out ||
|| Web Database Development Step by Step .NET Edition ||
|| Troubleshooting Microsoft FrontPage 2002 ||
|| Faster Smarter Beginning Programming ||
|| (All from Microsoft Press) ||
|/----------------------------------------------------\|
*------------------------------------------------------*