Skip to main content
Inspiring
September 28, 2008
Answered

Cold Fusion Sql not working properly

  • September 28, 2008
  • 3 replies
  • 704 views
When running the code through this function, it does not give me a syntex error and also does not actually delete any records either. There could be the possibility of deleting anywhere from 1 record up to hundreds... form.chk_email is a checkbox coming from the form submitting to get to this page. I want them to click on the checkbox to say what emails to delete from the db. Here is the code for the checkbox as well.
This topic has been closed for replies.
Correct answer MidOhioIT2
> Checkbox now:
> <cfinput type="checkbox" name="chk_email" value=
> "<cfoutput>#getclients.email#</cfoutput>" />

You might want to look at what HTML that generates. Because for me, the
mark-up for the resultant <input /> tag is this:

<input name="chk_email" id="chk_email" type="checkbox"
value="&lt;cfoutput&gt;foo@bar.com&lt;/cfoutput&gt;" />

(foo@bar.com is my test value for getclients.email)

You end up with your <cfoutput> escaped as part of the value in there.
This surprises me, I was expecting just an error there, because one cannot
embed a CFML tag within another one. In this case, the <cfoutput> is
completely unnecessary anyhow.

> <cfquery name="delclients" datasource="newsletter">
> select email from #guests# where email in
> (<cfqueryparam value="#form.chk_email#" list="true" cfsqltype="cf_sql_varchar">)
> </cfquery>

What does the debug for this query output? What's the value of the bind
parameter? How many rows does it return?

*Is it* returning anything?

--
Adam

I just found the issue it was with the checkbox on the form:

It should have been:
<cfinput type="checkbox" name="chk_email" value= "#getclients.email#" />

instead of
<cfinput type="checkbox" name="chk_email" value= "'<cfoutput>#getclients.email#</cfoutput>'" />

3 replies

Inspiring
September 28, 2008
In situations like this, change your DELETE query to a SELECT query with
the same filter, and see what results you get. It's easier to troubleshoot
the issue with a SELECT, because:
1) it displays results;
2) it's not destructive.

Once you sort the issue out, change the SELECT back to a DELETE.

If you have debugging on, it'll output the SQL actually being sent to the
DB driver, which also can help work out what's wrong.

--
Adam
Inspiring
September 28, 2008
Adam,

Here are the results, I for some reason do not get any results back when using the <cfqueryparam> function:
emails from form: '21312@fasdf.com','test@test.com'
emails from select2: test@test.com
emails from select2: 21312@fasdf.com
BKBK
Community Expert
Community Expert
September 28, 2008
What type of cfform is it? That is, is the value of the format attribute in the tag cfform set to HTML, XML or Flash?

When the format is HTML or XML the return value of a checkbox is the content of the value-attribute. Whereas, when the format is Flash, the return value is true or false.

Inspiring
September 28, 2008
BKBK,

Here is the line starting the form

Is this enough to answer your question? I am pretty new at cold fusion. I am a programmer however so this is why it is frustrating me.
Inspiring
September 28, 2008
When in doubt, look at your data. Start with
<cfdump var = "#form.chk_email#">
Do you see a list of whatever you are supposed to see?

Then run a select query and cfdump the results? Do you see any records?
Inspiring
September 28, 2008
Dan,


Here are my following results from the select:

emails from select: test@test.com emails from select: 21312@fasdf.com