Modifying a Record in a Database Using an HTML Form
In the last assignment, you inserted the data into the Access database by using an HTML form and an ASP page. In this assignment, you will create three pages. The first will display all the records. Next to each record there will be a link or form element that when clicked will take you to second page. The second page displays in an HTML form the contents of the record in the database that the user chose on the first page. The user can then make changes in the data displayed in the form. The third page takes whatever has been entered into the form (including any changes) and updates the record in the database with this information.
1. First Page - If you are using 3 tables in your Access database to represent the 3 categories of information. Since you will want to use a single page for your modification page, rather than create 3 similar pages, the first page must pass two pieces of information to the second page: the tablename and the primary key of the chosen record. If you are using a single table in your Access database to represent the 3 categories of information, you will again want to pass two pieces of information to the second page: the primary key of the chosen record and the category value for this record.
2. Second Page - The Dynamic SQL statements writeup may be helpful to you in creating a single modification page.
a) For the form, a text box -- i.e. that created with <input type="text"> has a size limit of 255 characters, just like a text field in Access. Just like you used a memo field in Access, use a textarea in the form. The syntax is
<textarea rows=5 cols = 50 name="bill"></textarea>
for a textarea which displays 5 rows and 50 characters per row. However, more text can be entered -- it just scrolls. You may want to use larger values for rows and cols.
b) When you used an HTML form to insert data, the page could be an HTML file. To modify data, you want to display the current contents of the record in a HTML form, so this page must be an ASP file because it will need to access the database as well as displaying an HTML form. To display the current contents in the form,
For textboxes: <INPUT type="text" name="bill" VALUE = "<% =rsname("fieldname") %>">
For textarea: <TEXTAREA rows=5 cols=30 name="bill2"><% =rsname("fieldname") %></TEXTAREA>
where rsname is the name of the recordset.
So that the ASP page that does the modification will know which record to modify, the form must pass the primary key to the next page -- this should be done as a hidden form field so that the user can't modify it. The value attribute of a hidden form field is specified the same way as it is for textboxes. If you are using 3 tables in Access, the form must also pass the tablename to the next page -- again as a hidden form field -- so that the next page will know in which table the modification should occur.
3. Third Page - The ASP page that does the modification will take the form information that is passed from the previous page and modify the record in the database. On the ASP page that does the modification, create a link to the ASP page you created in the previous assignment that displays the data-driven page. This way you and I can easily see the effect of the insertion by clicking on this link.
4. Create links to your pages in this assignment from your index file, including links to the .txt version of any ASP pages, and FTP your pages to your website.
Due: Wednesday, October 16. Each of you should do this on your own, but of course feel free to ask for help from me or others if you get stuck.
Revised: October 25, 2002