Updating an entry from your "Recent Updates" List

So you've just added a nice new entry to your list and Shock! Horror! you've made a spelling mistake! Or maybe you've made more additions to your site later in the day and would like to append to an existing entry. Either way, we need a method for updating an entry.

Like the Insert and Delete Record server behaviors, Dreamweaver MX comes to the rescue with an Update Record server behavior.

The process of updating a record is very similar to that of deleting one - that is to say it comes in two stages:

1. Find the offending item
2. Update it.

Stage 1: Finding the record

Finding a record to edit is exactly the same process and finding a record to delete. If you've not read the delete tutorial yet, now would be a good time to glance over it. Instead of duplicating one page with another, we'll go back and enhance our list page by adding an Edit link alongside the Delete one.

Just like we did with the Delete link, you need to create an edit page and link to it.

Click the Parameters button and create a new parameter called "id". Set it's value to "newsID" using the lightening bolt icon.

The page should now look something like this

Next, we're ready to build the guts of the edit page.

Stage 2: Update the record

This page needs to do a number of things:

  1. Create a recordset based on the output of the previous page
  2. Display the date for visual confirmation
  3. Display the current information in a text box for editing
  4. Provide a button to perform the update.

In the new edit page, define a Recordset like we did before.

The important thing about this recordset is that it uses a filter. The filter as shown above is based on the newsID field. The recordset is going to be filled with any records where the newsID field matches the id parameter passed through to the page on the query string. As newsID is always unique in the database, we should only get one record in our recordset.

We now need to create a form with a field for every database column that we want to update. For the Recent Updates list, we only have one column which will need updating - 'newsText' - so I'll create a form with one text field and a submit button.

I've named my textfield 'newsText' to correspond to the column name in the database.

The next thing we need to do is to enter the current value for the 'newsText' column into the text box. This will make it easy to make changes to the text without having to retype it all.

Just as you would insert normal data items on to the page, you can insert one into a text box. I find it most comfortable to grab the item from the Data Source window and drag it into the text box.

I'll also insert the Date field onto the page as a visual confirmation for the user. It's a good design tip to make the user feel as comfortable about what they're doing as possible when asking them to fill in a form. Being able to see the date of the item will help to reassure the user that they are making changes to the correct record.

All that's left to do now is apply the Update Record Server Behavior.

The Update Record dialogue box looks like this:

You'll notice that most of the fields are black until you select your Connection at the top. Once you've done that, most of the other fields will work out reasonable values for you.

Once your connection, table and recordset are selected, the important bit is mapping your form fields to the database columns. Because we gave our field a name which corresponded to the database column name, Dreamweaver MX has picked that up and made the mapping for us.

Pay special attention to the second box next to the Column heading. This lets you choose the data type. For our circumstance it's just Text - but for your own projects make sure you make an accurate selection otherwise your Update may not work. Special care is needed if you are inserting a date field or if your field is a checkbox.

Lastly, choose a page to redirect to after the Update, and click OK.

Let's see how it looks..

and then ...

and finally ...

It really is as simple as that.

Return to the index »