The mgiDatabaseUpdate Tag

Tag Behavior

The mgiDatabaseUpdate tag modifies an existing database record with information from a form submission. The mgiDatabaseUpdate tag allows a record to be modified without full administrative control of the database.


Tag Syntax

The mgiDatabaseUpdate tag has two required parameters and three optional parameter. The tag form is:

<mgiDatabaseUpdate databaseFileLocation="File Path"
tableName="Table Name" writeEmptyValues="Yes/No" mode="Mode" 
returnStatus="Yes/No">

Required Parameters:

  • databaseFileLocation="File Path" where "File Path" is the relative path to the database file that contains the records to be modified. The database name is case-sensitive.
  • tableName="Table Name" where "Table Name" is the name of the database table that contains the records to be modified. The table name is case-sensitive.

Optional Parameters:

  • writeEmptyValues="Yes/No" where "Yes" indicates that the data in database fields is erased for those submitted form fields that are left blank and "No" indicates that the data in database fields is kept intact for those submitted form fields that are left blank. The default is "No".
  • mode="Mode" where "Mode" is the current function of the mgiDatabaseUpdate tag. The "DeleteRecords" function finds all records in the database that matches the criteria in the key fields and deletes all records found.
  • returnStatus="Yes/No" where "Yes" displays the results of the database update and "No" does not display the results of the database update. A "Yes" is displayed if the database record was found and successfully updated. A "No" is displayed if the database record was not found or was not successfully updated.

Modifying Records - To modify a database record using mgiDatabaseUpdate, you must create a form page and a return page. The form page will contain form elements such as text fields, text boxes, radio buttons, checkboxes, and popup menus. Name any form element that is used to locate the record with the Key Field syntax. Name any form element that is used to modify a record with the Modification Field syntax. All fields and submit buttons on your form page should be enclosed by HTML form tags with an action that posts to the return page. The mgiDatabaseUpdate tag and required parameters should be entered on the return page.

  • Key Fields: Key Fields are used to locate the record that will be modified. When information is submitted in a Key Field, the database is searched and the first matching record will be modified. To insure that a specific record is located and modified, you can use a database field with unique data or use multiple Key Fields in the form. If multiple Key Fields are included, an AND search will be performed and the first record that matches the criteria in ALL Key Fields will be modified. At least one Key Field is required. The syntax of a Key Field is:

name="keyfield=DatabaseFieldName"

The database field names are case-sensitive.
  • Modification Fields: Modification Fields are used to update the record that matches the Key Field search. You may modify any or all database fields for a particular record. When the form is processed, only Modification Fields that contain information will be updated in the database record. If a Modification Field is left empty, the information in the corresponding database field will not be updated. The syntax of a Modification Field is:

name="field=DatabaseFieldName"

The database field names are case-sensitive.
  • Updates with Page Variables: On the return page (that contains the mgiDatabaseUpdate tag), you can use a page variable(s) to locate records (key fields) or update database fields (modification fields) with the page variable value. To locate records with a variable, enter a page variable in the HTML above the mgiDatabaseUpdate tag. Name the variable with the syntax name="keyfield=DatabaseFieldName". Note: you cannot modify the database with a form field (post argument) AND a page variable with the same name. For example, to locate the record of a particular client in the "Client" database field, enter the following page variable above the mgiDatabaseUpdate tag:
<mgiSet name="keyfield=Client">
Client A
</mgiSet>
To update a database field with a variable, enter a page variable in the HTML above the mgiDatabaseUpdate tag. Name the page variable with the syntax name="field=DatabaseFieldName". You can use multiple page variables to update multiple database fields. For example, to submit the current date to the "Last Modified" database field, enter the following page variable above the mgiDatabaseUpdate tag:
<mgiSet name="field=Last Modified">
<mgiDate>
</mgiSet>


Example Usage and Output

In this example, a form page and return page have been created to update pricing information for products. On the following form page, there is one Key Field (SKU) and one Modification Field (Price). The Key Field is named with the name="keyfield=DatabaseFieldName" syntax. The Modification Field is named with the name="field=DatabaseFieldName" syntax. The action of the HTML form tags that enclose the form fields and submit button is the name of the return page (return.html).

<FORM ACTION="return.html" METHOD="POST">
<H3 ALIGN=CENTER>Price Update</H3>
Search for SKU: <INPUT NAME="keyfield=SKU" TYPE="text" SIZE="30">
Updated Price: <INPUT NAME="field=Price" TYPE="text" SIZE="30">
<INPUT TYPE="submit" NAME="Submit">
</FORM>

The return.html page contains the following mgiDatabaseUpdate tag:

<mgiDatabaseUpdate databaseFileLocation="Catalog"
tableName="Products">

If an authorized visitor entered FJ8392 in the SKU Key Field and entered 5.99 in the Price Modification Field, the price of the first record (in the Products table of the Catalog database) that matched the SKU FJ8392 would be updated to 5.99.


Suggested Usage

  • Database Modifications


[Return to the Referencing MGI Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]