Hi,
is it possible to submit a form to the database (Access) and after the submit button is clicked another asp page loads with the data that has just been submitted, displayed.
Yes, but since you are displaying it again, you may want to use the form itself to display the items.
<%
set objCn = server.createObject("adodb.connection"
set objRS = server.createObject("adodb.recordset"
objCn.Open yourConnectionString
if request.servervariables("HTTP_METHOD" = "post" then
uName = request("uName"
uPhone = request("uPhone"
strSQL = "INSERT INTO myTable (uName, uPhone) "&_
"VALUES ('" & uName & "','" & uPhone & "')"
objCN.execute(strSQL)
end if 'since you already have the info, you don't need to query the db to get it and display it
objCn.close
set objCn = nothing
set objRs = nothing
%>
<form method=post action="thisPage.asp">
<input name="uName" value="<%=uName%>">
<input name="uPhone" value="<%=uPhone%>">
<input type=submit>
</form> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Do you have any other unique data in the table (other than ID)? I use stored procedures (w/ SQL Server) so I just use the @@identity feature. I don't think that you have that in access. Since that's not available you need to reselect the data you just entered and order by id desc...
if request.servervariables("HTTP_METHOD" = "post" then
uName = request("uName"
uPhone = request("uPhone"
strSQL = "INSERT INTO myTable (uName, uPhone) "&_
"VALUES ('" & uName & "','" & uPhone & "')"
objCN.execute(strSQL) strSQL = "SELECT TOP 1 * FROM myTable WHERE "&_
"uName = '" & uName & "' " &_
"AND uPhone = '" & uPhone & "' "&_
"ORDER BY pkID DESC"
set objRS = objCN.execute(strSQL)
if not objRS.EOF then
pkID = objRS("pkID"
else
response.write "An error has occurred"
end if
end if
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Be careful using Access to retrieve the identity key of the last item inserted. If the database is being accessed by more than one user simultanously you may not get back the correct key.
That's why I use SELECT TOP 1......ORDER BY pkID DESC
Hopefully only one set of exactly the same data gets inserted in the instant between executing the two queries. Of course, it could happen. Yet another reason that critical data usually requires something more than MS Access. Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
On the same tack is it possible to "POST" data through redirection?
Using Ultradev creates a "revisited" page with the contents of the form filled. I want to pass a field's contents on to the next page without appending it to the URL.But I can't find a way to resubmit a form from within the Code portion of the page.
You could put the form data in a cookie or session variable before redirecting, then on the next page read from the cookie/session variable? [Thanks in advance|Hope I helped you] Exodus300
' This is my advise
Set Conn = Server.CreateObject("ADODB.Connection"
Conn.Open dbConnection
set Rs = Server.Createobject("ADODB.Recordset"
Rs.Open "yourTable", Conn, 2, 2
Rs.Addnew
Rs("field1"=valueforfield1
Rs("field2"=valueforfield2
...
Rs.Update
Rs.Movelast
this_is_your_key_id = Rs("Autonumber_ID"
Rs.Close
Set Rs=Nothing
Conn.Close
Set Conn=Nothing
Response.Write this_is_your_id 'which was given out after you have inserted the values in a new record of your table.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.