Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cfquery weirdness

Status
Not open for further replies.

kelani

MIS
Nov 29, 2000
44
0
0
US
Okay, I have a million queries using update, insert,and delete, but this one is not working, and I don't know why. I've tried copying in a different form/query to see if i had some weird syntax error, but it doesn't work.. Here goes.

<cfif ParameterExists (Delete)>
<cfoutput>
<cfquery name=&quot;killmail&quot; dbinfo>
DELETE from mail WHERE mid='#form.mid#'
</cfquery>
Goodbye
</cfoutput>


and the corresponding form..

<form action=&quot; method=&quot;post&quot;>
<input type=&quot;Submit&quot; value=&quot;Kill It&quot; onMouseOver=&quot;window.status='Destroy this Letter'; return true&quot;>
<input type=&quot;hidden&quot; value=&quot;mid&quot; value=&quot;#mid#&quot;>
</form>


-
in the code for &quot;read mail&quot; the hidden form has the correct MID. It's just passing to the delete quesy for some reason.

Weird?
 
I would first verify that the <cfif> is actually executing. Names such as &quot;delete&quot; tend to be reserved words in programming languages and this may be keeping the <cfif> from executing. I can't find a list of CF reserved words but I would try changing the &quot;delete&quot; variable to something like &quot;del&quot; as this may be causing your problem.

Also, ParameterExists() is provided for backwards compatibility and should be replaced with IsDefined(). I don't use ParameterExists but I would try using Isdefined or changing to ParameterExists(url.delete) in case it requires the full scope.

If neither of these prove to be the problem, I would first verify the <cfif> is executing by putting some output text inside like <cfif ParameterExists()....> We're Here! <cfquery ... </cfif>

If you know you're getting inside the loop, I would do a hard coded query like:
<cfquery name=&quot;killmail&quot; dbinfo>
DELETE from mail WHERE mid='23'
</cfquery>
If this doesn't delete the record, then I would verify mid is a text field, dbinfo points to the correct database, etc...

If none of this helps, let me know and I'll try to duplicate on my system as I guarantee I can eventually fix this one ;)

GJ
 
Ok master, here are the results from our experiment..

1. Changing to IsDefined still gives the error.
2. changing to url.ParameterExists gives the error
3. Hard coding the delete query works fine :(
4. database info is the same as the other 20something queries on the page :)
5. MID is a unique ID that is an integer. by cselecting that, i'm killing that particular message row (id, sender, recip, sent, new, data)

would that matter?

It's just a simple query :)

thanks again, GJ
 
Because MID is an integer, your delete query doesn't work... NEVER put single quotes around an integer in a SQL query. Use this:

<cfquery name=&quot;killmail&quot; dbinfo>
DELETE from mail WHERE mid=#FORM.Mid#
</cfquery>

Good luck...
<webguru>iqof188</webguru>
 
Greetings,

I know you don't put single quotes around it, but I've tried it *without* them, and that doesn't work either. Here's the code as you describe it..

<cfquery name=&quot;killmail&quot; datasource=&quot;db26401a&quot; dbtype=&quot;ODBC&quot; username=&quot;us26401a&quot;
password=&quot;dxm714&quot; dbserver=&quot;localhost&quot; dbname=&quot;db26401a&quot;>
DELETE from mail WHERE mid=#mid#
</cfquery>

<form action=&quot; method=&quot;post&quot; name=&quot;Del&quot; id=&quot;Del&quot;>
<input type=&quot;Submit&quot; value=&quot;Kill It&quot; onMouseOver=&quot;window.status='Destroy this Letter'; return true&quot;>
<input type=&quot;hidden&quot; value=&quot;mid&quot; value=&quot;#mid#&quot;>
</form>


Still no go :(

Kelani
 
You aren't defining what should be deleted by the query. Can't you use something like:
<cfquery name=&quot;killmail&quot;>
DELETE *
FROM Mail
WHERE mid = #form.mid#
</cfquery>


Wouter
zure_zult@hotmail.com
To me, boxing is like a ballet, except there's no music, no choreography, and the dancers hit each other.
 
Wouter (is that your real name ;-) ), you don't need the asterisk (*) in DELETE queries, since DELETE will remove the entire record. If you only want ot delete a column, use UPDATE.

Kelani, I found the problem. GunJack and me must have been blind :). Take a look at your code:

<input type=&quot;hidden&quot; value=&quot;mid&quot; value=&quot;#mid#&quot;>

It has two values(mid and #mid#), I guess you mistyped it and did mistake name for value. Syntax should be:

<input type=&quot;hidden&quot; name=&quot;mid&quot; value=&quot;#mid#&quot;>

I'm sure this will help...



<webguru>iqof188</webguru>
 
I think we have a winner. If the hard coded query worked and the dynamic one doesn't, about the only cause is the variable not getting passed correctly which IQ seems to have found the reason for.

GJ
 
Hmm. That would fix the problem. Funny thing, I replaced that form a doxen times, with other *working* forms. So if that's the winner, I'm obviously a loser here.

Thanks everyone. I think i'll write a validator especially for this as penance. :)

Kelani
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top