decorative banner

Creating new records in a database


    There are two basic approaches to adding new records to a database. In the direct approach, the viewer fills out some fields of a form, clicks on a form submit button, and the record is added. The Add Record action supports this direct approach.

    In the second approach, the viewer is usually viewing a database record on a form and is presented with the possibility of updating that record. In addition, the viewer is presented with the possibility of creating a copy of that record's data or creating a new record from scratch using the same style of form. The viewer, in this case, selects such a choice, gets a new form page to be filled out, and then clicks a submit button to add the record. The Clear Form Data and Copy Form Data actions are used on the initial page to support this approach, followed by either the Update Record or Add Record actions on the second page.

To set up a form for direct record update:

  1. Create the form and fields for the user to enter data.
  2. Add a content source to the page connected to the database to be updated.
  3. Bind the form elements to fields in the content source.
  4. Add a form Submit Button to the form and select it. It is usually a good idea to set the label to a string appropriate to the function of the page. For example, Add New Request could be used as a button label of the button if it added a new record to a table of requests to be processed. This is set in the Inspector.
  5. In the Dynamic Bindings palette, set the form action to Add Record. This is a second level menu item under ADO Database for ASP, MySQL for PHP, and JDBC for JSP.
  6. Set the Content Source to the content source that references the table to which the record should be added. This must be the same content source to which form elements are bound. There must be at least one form field bound to that content source.
  7. If the design of the interaction dictates that the next page the user sees after pressing the form submit button is the same page from which they are submitting the new record, you do not need to set the redirect URLs. If not, you can define the next page to be displayed after the record is added, and the next page to be displayed if there is an error adding the new record.
  8. You can have more than one submit button on the form, each with a different action.

    Usually, when a form is being displayed for creating a new record, you want the fields to be blank. Binding them to content source fields causes the values from the database to appear. (See Creating a blank form for adding new records to a database for details on how to make the form blank.)

    Tip iconOnly data from bound form controls participate in the database action. If you have hidden form fields bound to fields of a content source, they will also contribute data to the form Action. Bound text or other bound elements in the form will not end up as part of the new record.

    Be very careful of how fields not present in the form are handled in the database. If a field is not on the form, it must have allow zero length, not required, or default values specified. Otherwise, difficult-to-diagnose errors may result because the database will reject the update.

    Make sure you have set up proper database permissions for the Web server to make updates or for the identity specified in data source. Remember that when your action is being processed on the server, the Web server's identity is used to validate file access. The Web server's identity is also used to validate database access unless there is another identity specified as part of the data source.