Generating a Customer List for Updating

I l @ ve RuBoard

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.

  1. 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.

  2. Add the following query to the top of the page:

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

    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.

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

     <font size="2">Click a name to update the product</font>  <p> <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.

  4. 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.

  5. 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.

  6. Save the file as productmenu.cfm in the Lesson6\Start folder on your hard drive. Open a browser and type http://127.0.0.1/Lesson6/Start/productmenu.cfm 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.

I l @ ve RuBoard


Macromedia ColdFusion 5. Training from the Source
Macromedia ColdFusion 5 Training from the Source (With CD-ROM)
ISBN: 0201758474
EAN: 2147483647
Year: 2002
Pages: 99
Authors: Kevin Schmidt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net