|
BeTheBall -> RE: Creating A form used to update my Database (9/25/2004 21:54:24)
|
The easiest way to do that is to create the form with the database results wizard. I am making the assumption that you will have some sort of link or form that will carry the ID of the record to your update form. Then, to create the form, open a new page. Click Insert - Database - Results. This launches the database results wizard. In step 1, choose the connection to your database. Step 2, choose your table. In step 3, choose only those fields you want the user to be able to update. For example, you don't want the user trying to change the ID of the record, so exclude it from the values you want to display. Once you select the fields to display, click More Options - Criteria - Add. This is where you determine which record you are going to edit. Since we will pass the ID number in from a link or form, choose ID - Equals - ID and leave the "Use this search form field" checkbox checked. Then, click OK three times followed by "Next" to move to Step 4. In Step 4, choose the formatting option of, "List - One field per item". Then, in the dropdown labeled, "List Options", choose "Text fields". Move to step 5 and choose "Display all records together" and UNCHECK the "Add search form" box. Click finish and save with a .asp extension. Now, since we excluded the field that displays the ID, we must add it as a hidden field so when we perform the actual update, the code knows what record it needs to update. To add the hidden field, right-click the form and choose, "Form Properties", then "Advanced" and the "Add". Under the name, enter "ID" and under the value, enter <%=FP_FieldHTML(fp_rs,"ID")%>. Finally, right-click the form again and again choose "Form Properties". Then click the "Options" button and under "Action", enter the name of a new .asp page whereon we will place code to update the record, something like Update.asp. That will give you your form prepopulated with the data from whatever record's ID is passed to the page. Now open a new page. Again choose, Insert - Database - Results. Step 1, choose your database connection. Step 2, mark the "Custom query" radio button and click the "Edit" button. Now, this is where you have to insert the query that will update the database. The format is this: UPDATE TableName SET dbfield1 = '::formfield1::', dbfield2 = '::formfield2::' WHERE ID = ::ID:: When you finish entering your query, click the "Verify query" button. If it verifies, proceed to Step 3. In step 3, click the "More Options" button and replace the "No Records Returned" message with "Update Successful!", or something like that. Then proceed to Step 5 where you should mark the "Display all records together" radio button and unmark the "Add search form" box. Now, you may wish to modify the form itself to replace text boxes with say a textarea or dropdown, but I would see if you can tackle this first and then edit the form later. Good luck!
|
|
|
|