FMStudio Complete Guide Chapter 7
From FMWebschool Reference
Contents |
Chapter 7. Adding Records to Your Database
Adding records with FMStudio is a relatively simple process. It consists of a blank form that will submit some information that will go into the new record. That information from the form is submitted to a response page, which will take the information and create a new record in the database.
You can then use the new record to display information about it such as its unique ID or an order confirmation number directly on the page.
- Begin by creating the blank form. To do this we will need to create a new PHP file named 'new_photo.php'.
- Just like on the search forms we will be using the form wizard to create a blank form. Make sure your cursor is flashing in the design view and then Navigate to Server Behaviors > Wizards > Form Builder. The form builder dialogue window will appear.
Creating the Form
- Give the form the name 'new_record' and click the check box for 'Generate a Table'.
- Use the 'Photos' connection for database
- The layout will be 'photos'
- For the action, just like with the search forms this is the response page – so it will be 'new_photo_response.php'.
- The Method will be set to POST
- The submit button text will be 'Create Record'
- Add three fields, 'photoName', 'photoDescription' and 'photoPrice'. Then click 'OK'
Image 7 – 1: Form builder with three fields added - 'photoName', 'photoDescription' and 'photoPrice'.
Next let’s make some aesthetic changes to the page by bolding and enlarging the ' text at the top of the page, and changing the field titles in the form to ‘Name’, ‘Description’, and ‘Price’.
Image 7 – 2: Change the field descriptions to Name, Description, and Price.
We’ve just created 'new_photo.php' which contains a blank form. All that is left now is to save this page and then create the response page.
- Let’s create another PHP page and name it 'new_photo_response.php'. On this page the first thing that we will do is create the database query that creates a new record.
- Navigate to the Server Behaviors > FileMaker Queries > New Query. The New Query dialog Window will open.
Image 7 – 3: Select Server Behaviors > FileMaker Queries > New (Query)
- First we will give the query a name (just like with the recordset, the same naming conventions apply) 'new_photo'.
- The connection is 'Photos'
- The layout will be 'photos'
- Under 'Add Fields' you will have to choose which fields that you want to enter inside the query. If you have fields that are automatically filled by FileMaker, you would not want to select them here. Only the fields that you want to input before committing the record should be added.
- The 'new_photo.php' page form includes the photo name, description and price. These fields need to be added by selecting the field name from the dropdown and clicking the ‘Add’ button.
- Start by selecting 'photoName' from the dropdown and clicking the 'Add' button. The Variable Selector window will appear. The top two values should read 'REQUEST' and 'photoName'. The other values can remain blank. I will repeat this for 'photoDescription' and 'photoPrice'.
Image 7 – 4: The new query should contain the following fields – photoName, photoDescription and photoPrice.
Now when the new record is created, a number of fields will be auto entered, as well as these three specific fields. They will be entered with whatever values were submitted from the new photo form. Once all of the required information has been entered, click 'OK'.
Once the new query has been added to the page, you can actually use this page to display some information about it. A good example would be a 'Thank You' page after some action has taken place.
- Let’s add 'Thank You for Adding a Photo' to the top of the page, and then add 'The new Photo ID is:' text underneath.
- From the Bindings tab I will select the 'photoID' binding and drag it beside the text that says 'The new Photo ID is'.
- Lastly add a style Header of 1 to the top text and a Header 2 to the last row of text and center them on the page.
Image 7 – 5: Style Heading of 1 applied to the topmost text, and a style Heading of 2 added to the lower text and the binding.
Note: When you have a new query, an edit query or a recordset under bindings you can use all of these to drag and drop the dynamic fields onto the page. With a new query, all of the values and the calculations are already reflected in the field values after the record has been created with whatever values you entered.
Note: Whenever you are initiating new queries or edit queries the bindings from the query reflect all of the updated values and calculations within that record. If you wanted to also show the previous value before the edit, then you would also need the recordset that would first find those values and display them.
Now that we have the new query on the 'new_photo_response.php' page and the 'photoID' binding displayed on the page, we can test the page to make sure that it works. Remember this is a response page; therefore you do not preview it in a browser directly.
To view this page in action you will need to open the 'new_photo.php' page in the browser and then fill out the form.
Open the ‘new_photo.php’ page in the browser, and enter some sample text into the text fields. In this example I will enter, Test Photo and then press the 'create record' button.
Image 7 – 6: Enter some test data to make sure the page is functioning properly
Once the 'create record' button is pressed, we will be taken to the 'new_photo_response.php' page. The 'new_photo_response.php' will verify that a new record has been added and also display a new photo ID.
Image 7 – 7: The 'new_photo_response.php' page informs us that a new record has been added and gives the new photo ID.

