FMStudio Complete Guide Chapter 9
From FMWebschool Reference
Contents |
Chapter 9. Deleting Records
Deleting records is a very straightforward process with FMStudio. It involves taking a link to a delete page –and then a delete query that finds and deletes a specific record from the database.
Let’s start off this chapter by working with the 'photo_detail.php' page. This page already has an 'Edit' link.
- Start off by adding a 'Delete' link on this page.
- Type the word 'Delete' beside the 'Edit' link.
Highlight the word 'Delete' and under Server Behaviors > Links > choose Dynamic Data Link. The Dynamic Data Link dialogue window will open.
Image 9 – 1: Choose Server Behaviors > Links > Dynamic Data Links to create a Dynamic Data Link on the page.
- Name the Target Page 'delete_photo.php'
- The variable name will be 'photoID'
- For the Variable Value choose the 'photoID' from the bindings. Then click 'OK'.
Image 9 – 2: Choose the ‘photoID’ binding from the photo Recordset
- With the Delete Link in place on 'photo_detail.php', save this page and then create the next page, 'delete_photo.php'.
Since delete is a query that affects a specific record, it expects the internal recordID of FileMaker to know which record to delete. In this case, this page will actually be doing double duty. It will be finding a specific record based on the photoID (This is not the internal ID) and then using the found record that is based on the photoID to provide the recordID of that record to the delete query. This page will need to start with a recordset.
- Create a new recordset and name it 'photo'.
- Use the 'Photos' connection
- The layout will be 'photos'
- The Add Criterion will be 'photoID' and will be an exact search for the photo ID.
- Click the 'Add' button, the Type should be 'REQUEST', the Name should be 'photoID' and the Operation should be '= ='. The last step is to disable wildcards and click 'OK'.
Image 9 – 3: Completed Find Recordset
Now that the recordset is in place, we will be able to use its special metadata bindings in order to delete the record. In the next few steps, we will add the delete query to the 'delete_photo.php' page.
- Under Server Behaviors, choose FileMaker Queries and then choose Delete. The Delete dialogue window will open.
- Name the query 'delete_photo', and use the 'Photos' connection.
- Select the layout from which to delete the records. That layout is 'photos'.
- Choose the 'Select' button. The Variable Selector dialogue window will open.
- From the Type drop down list, choose 'Recordset (photo) Meta-Data’.
Image 9 – 4: From the ‘Type’ dropdown list, choose 'Recordset (photo) Meta-Data’.
- Then choose the second drop down menu to select the RecordID. Do not select any extra operations. Once this is completed, click ‘OK’.
Image 9 – 5: The completed Delete dialogue window
This may cause some confusion, as you have just created a delete query, yet there is nothing showing up in the Dreamweaver work area. The Delete Query has actually been created; you will be able to see it under Server Behaviors.
Image 9 – 6: The Delete Query shows up under Server Behaviors not directly on the Dreamweaver work area.
Since the record is being deleted there is not much you can show to the user, the record itself is gone. So, you may want to show a quick message. Such as 'Thank you, this record has been deleted.'
- Let’s go ahead and add that text to 'delete_photo.php', center it on the page and apply a Heading 1 style. Once we are finished making the changes to the page, it's important to save the page.
- To test the new Delete Process, we need to open the 'search.php' page in the browser and navigate to 'photo_detail.php'. Once we have found a record, and navigated to the detail page, we are presented with a table displaying the details of a single record with 'Edit' and 'Delete' links below the table.
When I click the 'delete' link,
Image 9 – 7: Click the delete link to delete this record – you will be automatically redirected to the ‘delete_photo.php’ page.
The record is deleted from the database and you will automatically be redirected to a page that says, "Thank you this record has been deleted", this is the 'delete_photo.php' page.
Image 9 – 8: The text displayed on the ‘delete_photo.php’ page.
Now that you have seen how the delete works with a confirmation method, let’s apply the same redirect technique that we used when editing a record. Instead of going to a secondary page, the visitor to your site, once choosing edit or delete, will be taken back to another page, such as the detail page or even the search page. In this example, we will take the visitor back to the search page.
- Go back to the 'delete_photo.php' page and under Server Behaviors choose Page Actions Redirect. The Redirect Dialogue window will open.
- For the Redirect URL type 'search.php'. No variables are needed in this case since the user is just taken to the search page.
- Save this page.
- Testing this process. Open 'photo_detail.php' in your browser, and click on the 'delete' link this should delete the record. To verify that the record has been deleted from the database, you can perform a search for that record from the 'search.php' page.
Image 9 – 9: Click delete to delete the record. To confirm that the page is working correctly, search your database for the record, or perform a search for the record from the ‘search.php’ page.

