Creating the Insert Transaction

Creating the Insert Transaction

Getting started

First create, in your site root folder, a new file named "insert.php". Then, in the "index.php" file, insert a link named "Add", pointing to the record insertion page named "insert.php". To create a link, select the "Add" text, use your right mouse button and select the "insert.php" file from the list displayed by Dreamweaver.

Creating an Insert Transaction

A transaction, in the tNG context, represents a basic operation on a database.

Open the "insert.php" file and create an Insert Transaction. To do that, go to "ImpAKT2" tab from "Insert" panel and press the "tNG Insert From" button (first icon from the left).

Dreamweaver MX will display the transaction User Interface:

We will continue by explaining the parameters of the interface, to help you understand how it has to be configured for a correct functioning.

Insert Transaction parameters

Transaction Name: a unique name in the page context. A textual representation of the transaction in the source code and the Dreamweaver User Interface.

Connection: the connection that will be used to execute this transaction

Table: the table in which we want to insert some records. We will select "departments_dep"

After inserting, Go To: a file to which the browser will be redirected if the transaction succeeded . We will select "index.php" to return to the main list.

Form Fields: the list of all the columns in the selected table. For each column we can move it up/down, remove it or add them to the insert. For each column we must select or set:

  • Variable type: this tells the transaction where to look for the variable (at execution time), for its value to be inserted in the database.

  • Name: this tells the name of the variable which contains the data that is inserted in each column

    • For example, we remove the first variable, "id_dep" from the list (being a serial type, auto-incremented, when inserting this values we don't need to specify an explicit value). For the "name_dep" column, we want to take the value from a form in which the variable is called name, we select "Form in page". The user interface updates itself with two drop downs containing all the forms in the page and for each form the fields inside it.

  • Data type: selecting this accurately for each field that you insert in the database will ensure increased error checking for its types. We select the types 驩УRING for the name variables and "NUMERIC" for the budget variable.

The command adds also a UniVal trigger that validates the form input.

ImpAKT 2 automatically gives a name to each new created transaction. However, this transaction name can be changed by the developer. Name this transaction "insertTransaction", then choose the "impaktbasics_conn" as connection and the "departments_dep" table as the transaction target table. Write the page to be loaded after the transaction is done (in our case being "index.php") in after inserting, Go To field. The "Unique Key Column" field must contain the "id_dep" field as this is the departments unique key.

Then we choose the "name_dep" field as being required and "budget_dep" as being required and having a "Positive Float" field type. That will cause an error message if the user will try to insert a blank name department or a non numeric value for the budget.

The Insert Transaction command user interface should look like in the picture below:

The "tNG Insert Form" command will generate the form, the Insert Transaction server behavior, the UniVAL trigger and the Handle error trigger. Also, a RollBack Insert trigger is generated. This last trigger will delete from the database any unnecessary data that might be written even if the Insert Transaction fails overall. We strongly recommend the use of this trigger for any new insert transaction created. This way you will protect your database from any possible disaster.

Now press the "OK" button and save your "insert.php" file.

Adobe acquired InterAKT
InterAKT has been acquired by Adobe.
Learn more
 
© Adobe Systems Romania. All rights reserved.