Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Setting CFPARAM default value

New Here ,
Oct 13, 2009 Oct 13, 2009

Hi,

I am working on a shopping cart site that I did not design.

The cart currently has 1 page for each product category so there is about 15 pages.  I want to reduce it to one page and carry the cat_id through the URL.  I am doing this successfully, however, when it comes to 'Adding and Item to the Cart' it loses the value for the cat_id and returns an error.

The following is the code I am using:

<cfparam name="url.cat_id" default="" />

<cfquery name="catalogue" datasource="#rxxxxx#" username="#xxxxxx#" password="#xxxxxxx#">
SELECT *
FROM products

WHERE prod_cat_id = #url.cat_id#

</cfquery>

However, when I change the code to the following (the difference is bolded), the cart works as expected:

<cfparam name="url.cat_id" default="9" />

<cfquery name="catalogue" datasource="#rxxxxx#" username="#xxxxxx#" password="#xxxxxxx#">
SELECT *
FROM products

WHERE prod_cat_id = #url.cat_id#

</cfquery>

My question is, is there a way to set the cfparam default value with the URL.cat_id value?

Any suggestions?

1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 13, 2009 Oct 13, 2009

If the  prod_cat_id is an integer value, then the default value of cat_id can be set to zero. Or you can add a condition to execute the query only if the

cat_id is not null. If you can specify the error thrown, it can give more idea about it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2009 Oct 13, 2009

Hi,

The error thrown is as follows:

ERROR EXECUTING DATABASE QUERY

Syntax error or access violation: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 14, 2009 Oct 14, 2009

Does your debugging info show you the sql that caused this error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2009 Oct 14, 2009
LATEST

Hi Dan,

Thanks for your help.  No it doesn't show the sql that caused the error.  It only goes on to say the resources that are available for example:


Resources:

  • Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debugging Settings, and select the Robust Exception Information option.
  • Check the ColdFusion documentation to verify that you are using the correct syntax.
  • Search the Knowledge Base to find a solution to your problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 13, 2009 Oct 13, 2009

What you are attempting is to set the value of the url variable to something you didn't receive.

Before looking to set a default value, ask yourself some questions.  First, under what circumstances could the page be requested without the url variable.  Next, what do you want to happen when it does?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 13, 2009 Oct 13, 2009

Make sure that your "Add an Item to the Cart" link/form also passes the category ID via your URL cat_id variable (not via a form field).

You may also want to consider using the <cfqueryparam> tag for added security in your query:

WHERE prod_cat_id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#url.cat_id#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources