<%
Const adVarChar = 200
Const adBoolean = 11
Dim rstUserData
' Normally this would be the result of a query something like this:
' SELECT * FROM TableName WHERE id=123;
' or:
' SELECT * FROM TableName WHERE email LIKE 'EmailAddressGoesHere';
'
' For simplicity, my recordset isn't actually connected to anything.
' Create the stand alone recordset
Set rstUserData = Server.CreateObject("ADODB.Recordset")
rstUserData.Fields.Append "Name", adVarChar, 50
rstUserData.Fields.Append "Email", adVarChar, 100
rstUserData.Fields.Append "Updates", adBoolean
rstUserData.Open
' Add the sample data to our recordset. Again, this data would
' normally be a result of a query against your database.
rstUserData.AddNew
rstUserData.Fields("Name").Value = "John"
rstUserData.Fields("Email").Value = "JohnsEmailWouldGoHere"
rstUserData.Fields("Updates").Value = True
rstUserData.Update
If Request.Form("save") = "Save" Then
' Save data from the form back to the recordset.
rstUserData.MoveFirst
rstUserData.Fields("Name").Value = Request.Form("name")
rstUserData.Fields("Email").Value = Request.Form("email")
rstUserData.Fields("Updates").Value = (Request.Form("updates") = "on")
rstUserData.Update
%>
<p>
Data updated. You can continue making chages via the form below or
<a href="<%= Request.ServerVariables("SCRIPT_NAME") %>">start over</a>.
</p>
<%
End If ' Else
' Display the form with the data from the recordset.
' If the user just saved the data, you might not want to show the
' form again. In that case change the "End If" above to an "Else"
' and uncomment the last "End If" on the page.
If Not rstUserData.EOF Then
%>
<form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post">
<table border="0">
<tr>
<td align="right"><strong>Name:</strong></td>
<td align="left"><input type="text" name="name" size="30" value="<%= rstUserData.Fields("Name").Value %>" /></td>
</tr>
<tr>
<td align="right"><strong>Email:</strong></td>
<td align="left"><input type="text" name="email" size="30" value="<%= rstUserData.Fields("Email").Value %>" /></td>
</tr>
<tr>
<td align="right"><strong>Send Me Updates:</strong></td>
<td align="left"><input type="checkbox" name="updates"
<% If rstUserData.Fields("Updates").Value Then Response.Write "checked=""checked""" %> />
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="reset" value="Reset" />
<input type="submit" name="save" value="Save" />
</td>
</tr>
</table>
</form>
<%
End If
' End If
%>