Okay, so you want to make an editable form on your web page that retrieves data from your database and allows the user to update their own info. For our example, let’s say you have a bunch of sales reps that work for your company. They login to their account on your website and want to update their personal information.
For this example, we will say that a sales rep logs in to your website using their employee ID number, which is in turn written to a cookie on their web browser.
First, we start off with our database connection and recordset code:
<!--#include virtual="/includes/connection.asp" -->
<%
DIM mySQL, objRS
mySQL = "SELECT * FROM tblSalesReps WHERE EmployeeID = " & intEmployeeID & " "
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn
%>
In this example, you could display the sales rep’s First Name and Last Name in two simple text boxes using this form this:
<form name="Update" method="post" action="updateconfirm.asp">
First Name: <input type="text" name="FirstName" size="50" value='<%=objRS("FirstName")%>' ><br>
Last Name: <input type="text" name="LastName" size="50" value='<%=objRS("LastName")%>' >
<input type="submit" name="Submit" value="Submit">
</form>
If you wanted to display a Sales Territory field that retrieves and lists all of the available sales rep territories from your database, you could display them with a drop down menu like this:
<form name="Update" method="post" action="updateconfirm.asp">
Territory: <select name="Territory">
<option selected><%=objRS("Territory")%></option>
<%
DIM strTerritory
DO WHILE NOT objRS.EOF
strTerritory = objRS("Territory")
%>
<option value><%=strTerritory%></option>
<%
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
%>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
This will display the sales rep’s saved sales territory and allow them to view all of the other territories in the drop down menu and choose another if needed.
Last, you may have a comment field in your database for your sales reps to make additional comments or notes. If you want them to be able to edit their comments, you could display them in a textarea box like this:
<form name="Update" method="post" action="updateconfirm.asp">
Comments: <textarea name="Comments" cols="50" rows="5" wrap="VIRTUAL"><%=objRS("Comments")%></textarea>
<input type="submit" name="Submit" value="Submit">
</form>
That’s it. Now, you have your very own editable form. If you need help with updating the record in your database, check out our Update Database Record script.