• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 6. Modifying Databases > Generating a Customer List for Updating

Generating a Customer List for Updating

Once you have information in the database, there may come a time when you need to update that information: correct a misspelled word, change a product price, or refresh an email address. Rather than having to add the new and delete the old, you are able to edit the existing information. You could physically change the information in the database, but using a Web interface with ColdFusion is much easier. You'll create that interface now.

Open productmenu.cfm from the Lesson6\Start folder on the CD-ROM.

In order to update product information, of course you must first select which product's information you wish to update. The products menu creates a list of the products currently in the database for you to choose from.

Add the following query to the top of the page:

<cfquery name="productselect" datasource="products"> 
select *
from tblProducts

This query selects all of the products that are currently in the database. The next step is to output the information and create a link for each product to the productupdateform.cfm page, where the information can be updated. This link will contain information specific to the product for which it is created. Each item's unique ID will be appended to this link.

Add the following CFML code to the body of the document:

<font size="2">Click a name to update the product</font> 
<cfoutput query=”productselect”>

By using the <cfoutput> tag with the query specified, you are going to loop over all the records in the tblProducts table. That takes care of getting the list of all products. Now you need to be able to choose the ones you want. For each one of these records, you will output the product's name and make that name a link to the update page.

Add the following CFML code after your <cfoutput> tag:

<a href=”productupdateform.cfm?productid=#productid#”>#productname#</a><br> 


When you create your link for each item, you must be sure to pass the value of the productid field to the next template (even though you are not going to display this variable). This is done through the URL.

Without this variable, there will be no way for the template to know what product record needs to be updated.

Add the closing </cfoutput> tag.

Now when you run the template you see a list of products. When you select the product you want to update, the productupdateform.cfm page will be called and the product's ID will be passed along.

Save the file as productmenu.cfm in the Lesson6\Start folder on your hard drive. Open a browser and type into the address window.

The list of products appears, each with a hyperlink to the update page. But if you were to click on one of those links now, you would get an error, as the productupdate.cfm template has not yet been created. That is the next step.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint