Server Time:
Monday May 12 2008 06:47 AM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Using Query String Values....
by: Pablo Varando
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

I was emailed earlier this week and asked if I could write a tutorial on how to insert data into a database with "query string" variables. 
[i.e. page.cfm?name=John&email=john@smith.com]

So I thought I would create a short tutorial demonstrating the use of different variables within a query.

The first thing you must remember is that a variable is a variable, whether it is being passes via a form or a URL query string. With that in mind I'll show you different ways that you can access variables.

Let's say you have a form that will allow a user to add their name and email to a database. You have to ways for passing the variables. The first example is the recommended way.

The first way to pass variables is via FORM submission. As seen below.

<!--- Form Page --->
<form action="process.cfm" method="post">
Name: <input type="text" name="myname"><BR>
Email: <input type="text" name="myemail"><BR>
<input type="submit" name="Go" value="Add Me">
</form>

What makes this form actually pass FORM variables is the method="post" defined in the <form> tag. So on the action page you would use the passed values and enter them into your database as follows:

<!--- Insert user --->
<cfquery name="qAddUser" datasource="MyDSN">
   INSERT INTO Users(
                              Name,
                              Email,
                             )
                    Values(
                               '#form.myname#',
                               '#form.myemail#',
                              )
</cfquery>

Notice that you are referring to the variables a form.variables. If you would remove the METHOD="POST" definition to the form page, then your form would be passed via URL query string variables. so using the #form.name# method wouldn't work, simply because they are no longer FORM variables, but instead URL Variables.

So, how do you reference URL variables? Well using URL.name of course :)

So if you have a URL quesrystring form then how would the <cfquery> above look then? Let's take a look:

<!--- Insert user --->
<cfquery name="qAddUser" datasource="MyDSN">
   INSERT INTO Users(
                              Name,
                              Email,
                             )
                    Values(
                               '#url.myname#',
                               '#url.myemail#',
                              )
</cfquery>

It's that simple. Now keep in mind that I don't personally suggest you use query string values. Simply because you'll have to pass the values in URL Encoded Format (What is URL Encoded Format?) which is just asking for trouble. Always use FORM variables, they're easier to work with and are always much more effective, not to mention they're also cross-browser [i.e Internet Explorer, Netscape, Opera, etc.] friendly :)

Well, there's also much more to this method (URL String values) such as URLEncodedFormat, URLDecode and more, If you are seriously looking to use URL formats, I suggest you familiarize yourself with these tags and their usage.


Date added: Sun. September 15, 2002
Posted by: Pablo Varando | Views: 33310 | Tested Platforms: CF5 | Difficulty: Intermediate
Categories Listed: Databases

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
Delete files and folders in a specified path!
This tutorial will demonstrate how you can delete all files and sub-folders in a specified folder using ColdFusion and Windows! - Date added: Wed. September 7, 2005
Dynamic Last Date Modified?
This tutorial will demonstrate how to display the date a web page was last modified to your visitors dynamically. - Date added: Mon. April 12, 2004
Correct Content (document) serving!
This tutorial will demonstrate how to correctly serve documents via ColdFusion and allow you to correctly name the download as you see fit! - Date added: Tue. February 10, 2004
Creating your very own RSS XML Feeds with ColdFusion MX!
Have you ever wanted to create your very own RSS XML News Feeds? This tutorial will show you how to create an RSS feed that will allow you to syndicate your web site and allow the world to easily use your data! - Date added: Thu. January 15, 2004
Processing XML/RSS feeds with ColdFusion MX
This tutorial will show you how to parse XML files (RSS Feeds) with ColdFusion MX and it uses an EasyCFM.COM Feed for example [Feed: 5 Most Viewed Tutorials]. It shows you how to call it via CFHTTP all the way to parse and display your records! - Date added: Sat. December 27, 2003

Additional Tutorials:
· Changing the form submission page on the fly!

· What is the ID for the record I just inserted?

· Creating a file content crawler with ColdFusion....

· Delete Records From Your Database With ColdFusion!

· Do you want to remember your members?

· Get A Folder Size Using ColdFusion and FSO...

· Preventing People From Leeching Your Images!

· Combining two queries into one..

· CaSe SensitiVe password logins!

· Creating an ODBC Connection within ColdFusion MX Server...

· Print your web pages on the fly!

· Using <CFPOP> and creating an email client for POP3 Email Reading!

· Using CFRegistry to Add Your IP To CF Debug IP List!

· Reading your IIS Log Files with ColdFusion!

· Automatically Adding Smiles To Your Messages!

· Using Arrays in ColdFusion To Properly Display Data....

· Implementing FORM Error Checking On Your Pages!

· Inserting FORM data into multiple database tables!

· Creating, Altering and Deleting database tables with ColdFusion.

· Sending multiple attachments with CFMAIL!

· ColdFusion and .INI Files!

· Clearing your session variables!

· Using PayPal's IPN with ColdFusion!

· Alternating Row Colors!

· Previous / Next n Records

· A quick intro into the world of Custom Tags!

· A brief demonstration of Fusebox 2.0

· Creating a Newsletter System....

· Count Active Users On Your Site.

· User Defined Functions....

· Creating a user athentication (Login) area.

· DSNLess Coldfusion?

· A Simple Contact Us Page….

· Having Your Database Do The Work… not ColdFusion!

· Retrieving Records From a Database..

· Inserting data into a database
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
I need help Please
Hi
I want to add URL address to open window method using JScript inside my XML but i got error messge related to reserved character in XML my URL like:
xxx?id=1&id2=2 the problem related to & character how can i solve this issue please
Posted by: humam
Posted on: 12/27/2007 12:18 PM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
ColdFusion Hosting by HostMySite

You are 1 of 707 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb