Using form values in query statement

  • Thread starter wildwatermelon12
  • Start date
W

wildwatermelon12

Hello~

I am building a form where a user should choose a category from a
dropdown menu populated from the "categories" table, and then a second
dropdown menu should appear if there are any subcategories available
for the selected category. I have joined the tables in Access so that
there is a 1-to-many relationship between the categories.id field and
the subcategories.categoryID field. This is the query that Access
generated, and I then added the WHERE statement to include the form
value that the user generates:

<cfquery name="getSubcategories" datasource="corpGov">
SELECT
categories.id
AS
categories_id, subcategories.id
AS
subcategories_id, subcategories.categoryID
FROM
categories
INNER JOIN
subcategories
ON
categories.id = subcategories.categoryID
WHERE
form.category.id = subcategories.categoryID
</cfquery>

This is the form code that I am using right now:

<cfselect name="category" message="Please choose a category!"
required="yes">
<cfloop query="getCategories">
<cfoutput>
<option value="#getCategories.id#">#getCategories.name#</
option>
</cfoutput>
</cfloop>
</cfselect>
</div></td>
</tr>

<!--- If Category defined above has Subcategories available,
display them in a dropdown menu --->
<cfif isDefined("form.category")>
<tr>
<td>
<div align="right">Subcategory :</div>
</td>
<td>
<div align="left">
<cfselect name="subcategories"
message="Please choose a subcategory!" required="yes">
<option>None</option>
<cfloop query="getSubcategories">
<cfoutput>
<option value="#getSubcategories#">#getSubcategories#</
option>
</cfoutput>
</cfloop>
</cfselect>
</div></td>
</tr>
</cfif>

I am getting the following error:

Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC
Microsoft Access Driver] Too few parameters. Expected 1.

If anyone has any suggestions, they would be very welcome! Thanks.

KC
 
W

wildwatermelon12

Hello~

I am building a form where a user should choose a category from a
dropdown menu populated from the "categories" table, and then a second
dropdown menu should appear if there are any subcategories available
for the selected category. I have joined the tables in Access so that
there is a 1-to-many relationship between the categories.id field and
the subcategories.categoryID field. This is the query that Access
generated, and I then added the WHERE statement to include the form
value that the user generates:

<cfquery name="getSubcategories" datasource="corpGov">
SELECT
categories.id
AS
categories_id, subcategories.id
AS
subcategories_id, subcategories.categoryID
FROM
categories
INNER JOIN
subcategories
ON
categories.id = subcategories.categoryID
WHERE
form.category.id = subcategories.categoryID
</cfquery>

This is the form code that I am using right now:

<cfselect name="category" message="Please choose a category!"
required="yes">
<cfloop query="getCategories">
<cfoutput>
<option value="#getCategories.id#">#getCategories.name#</
option>
</cfoutput>
</cfloop>
</cfselect>
</div></td>
</tr>

<!--- If Category defined above has Subcategories available,
display them in a dropdown menu --->
<cfif isDefined("form.category")>
<tr>
<td>
<div align="right">Subcategory :</div>
</td>
<td>
<div align="left">
<cfselect name="subcategories"
message="Please choose a subcategory!" required="yes">
<option>None</option>
<cfloop query="getSubcategories">
<cfoutput>
<option value="#getSubcategories#">#getSubcategories#</
option>
</cfoutput>
</cfloop>
</cfselect>
</div></td>
</tr>
</cfif>

I am getting the following error:

Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC
Microsoft Access Driver] Too few parameters. Expected 1.

If anyone has any suggestions, they would be very welcome! Thanks.

KC

OK, I figured out that I need to switch the order of my WHERE
statement so that it reads like this:

WHERE
subcategories.categoryID = form.category.id

But I am still getting the same "1 parameter" error. Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

If Statement in HTML 8

Top