Tuesday, 29 November 2011

POPULATE FORM FROM DATABASE

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 your secure website area and want to update their personal info. For this example, we will say that a sales rep logged in to our secure area with their employee ID number, which is in turn written to a cookie on their browser.

First, we start off with our standard connection and recordset code:



<%
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 reps first and last name in two simple text boxes by doing this:


First Name:

Last Name:



If you wanted to display a sales territory field that retrieves and lists available terriroties from your database, you could display them with a drop down menu like this:


Territory:



This will display the sales reps saved territory and allow them to view all of the other territories in the drop down menu and choose another if they wish.

Last, you may have a comment field in your database for your sales reps to make additional comments. If you want them to be able to edit their comments, you could display them in a textarea box like this:


Comments:



That's it. Now, you have your very own editable form. If you need help with updating the record in your database,

http://www.aspwebpro.com/aspscripts/forms/populateformfromdb.asp

No comments:

Post a Comment