| By Bruce Van Horn | Article Rating: |
|
| October 30, 2000 12:00 AM EST | Reads: |
7,315 |
Welcome to the second installment of this column. If you're a new reader, the purpose of the column is to give you another source for your CF-related questions.
Many of you have taken the ColdFusion classes offered by Allaire...and many of you haven't. If you have, you probably know how to get in touch with your instructor for answers to questions that may come up after the fact. However, if you haven't taken any CF classes, you can still "ask the training staff" and we'll be happy to respond.
Here are just a few of the questions that have been asked recently:
Q: I'm having trouble inserting a date into an MS Access database table. My SQL for the insert looks like this:
<CFQUERY DATASOURCE="msp" NAME="addReg"> INSERT INTO AttendanceInfo (StudentID,Date,FirstName,LastName) VALUES (#form.StudentID#,#CreateODBCDate(form.Date)#,'#form. FirstName#','#form.LastName#') </CFQUERY>
Can you help me?
A: The good news is that there's nothing wrong with your SQL statement. The problem is actually with your database; specifically, your database field called "date". While it's tempting (and even logical) to name a database column "date" (since that's what it's going to store), you can't do it because DATE is a reserved word in SQL. Simply rename the database column to something like "CourseDate" and then it'll work.
Q: I'm trying to set a cookie once my user has logged in to my site (see code snippet below), but the cookie is not getting set. I've tried everything I know. What do you suggest?
<!--- this code is part of loginAction.cfm ---> <CFIF GetLogin.RecordCount gt 0> <CFCOOKIE NAME="UserID" VALUE="GetLogin.UserID"> <CFLOCATION URL="../index.cfm"> </CFIF>
A: The problem has to do with using the CFCOOKIE and CFLOCATION tags in the same section of code. This code would work if you omitted the CFLOCATION and made the user click on a link to enter the site, or if you did a client-side (JavaScript or meta) relocation to index.cfm. It would work because the cookie travels back to the browser as part of the HTTP response that goes to the client. In this case loginAction.cfm would be returned to the browser and the cookie would get set. By using the CFLOCATION tag, which is a server-side relocation, the page that sets the cookie (loginAction.cfm) never goes to the client's browser, so the cookie never gets set. The only page returned to the browser after the login is index.cfm, which doesn't have a cookie attached to it. The bottom line is this: you can't use CFCOOKIE and CFLOCATION in the same page.
Q: How can I display a random record from our products table every time someone comes to our home page?
A:There are several ways to do this. The easiest way is to retrieve all the records (or some subset of records) and then let CF randomly pick one from the record set. Here's an overview, but look at the code in the snippet for exact syntax. First, run a query to retrieve all the products. Next, create a variable set to a random number between one and the total of all the records returned from your query. Last, randomly output the selected product.
<CFQUERY DATASOURCE="dsn" NAME="qProducts"> SELECT ProductID, Product_Description FROM Products </CFQUERY> <CFSET RandProd = RandRange(1,qProducts.RecordCount)> <CFOUTPUT QUERY="qProducts" STARTROW="#Variables.RandProd# "MAXROWS="1"> #qProducts.ProductID# - #qProducts.Product_Description# </CFOUTPUT>
Please send your questions about ColdFusion (CFML, CF Server, or CF Studio) to AskCFDJ@sys-con.com.
Published October 30, 2000 Reads 7,315
Copyright © 2000 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Bruce Van Horn
Bruce Van Horn is president of Netsite Dynamics, LLC, a certified ColdFusion developer/instructor, and a member of the CFDJ International Advisory Board.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF


























