LelloLello
asked on
UPDATE Table Set .... Where ??
I have the following update in coldfusion.
My CMTEE_pref will not be updated because the where statement is not correct.
<CFIF #FORM.CMTEE_PREF# NEQ "">
UPDATE cvitool
SET
CMTEE_PREF = #FORM.CMTEE_PREF#
WHERE users.user_id=#FORM.user_i d#
</CFIF>
Could you please advice how i can adjust that according to my cfquery.
FROM users INNER JOIN cvitool ON users.id_number = cast(cvitool.id as INT)
WHERE users.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer" >.
My CMTEE_pref will not be updated because the where statement is not correct.
<CFIF #FORM.CMTEE_PREF# NEQ "">
UPDATE cvitool
SET
CMTEE_PREF = #FORM.CMTEE_PREF#
WHERE users.user_id=#FORM.user_i
</CFIF>
Could you please advice how i can adjust that according to my cfquery.
FROM users INNER JOIN cvitool ON users.id_number = cast(cvitool.id as INT)
WHERE users.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Agx,
thank you for your reply.
I've add the following
<CFIF #FORM.CMTEE_PREF# NEQ "">
UPDATE cvitool
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#"
cfsqltype="cf_sql_varchar" >
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer" >
</CFIF>
But the update of the field CMTEE_PREF is not updating that field in the database.
could you please advice.
thank you for your reply.
I've add the following
<CFIF #FORM.CMTEE_PREF# NEQ "">
UPDATE cvitool
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#"
cfsqltype="cf_sql_varchar"
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer"
</CFIF>
But the update of the field CMTEE_PREF is not updating that field in the database.
could you please advice.
Is your real code missing the cfquery tags? It won't do anything without those ;) Also, you're using VARCHAR for one of the values. Aren't they both integers? Using the correct type is important. See my example above.
If your real code DOES have cfquery tags, possibilities why it isn't working are:
1) it's not running the UPDATE code at all. Add an else condition to debug what's happening
<cfif len(trim(FORM.CMTEE_PREF)) >
running update query.
<cfquery ...>
Your update code here
</cfquery>
<cfelse>
it's empty. do nothing
</cfif>
2. If it IS running the update, but not changing the value then it means the database didn't find a record matching your criteria. So you need to find out why. Add a result attribute to the query and dump it to see the generated sql
<cfquery result="yourResult" ...>
Your update code here
</cfquery>
<cfdump var="#yourResult#">
If your real code DOES have cfquery tags, possibilities why it isn't working are:
1) it's not running the UPDATE code at all. Add an else condition to debug what's happening
<cfif len(trim(FORM.CMTEE_PREF))
running update query.
<cfquery ...>
Your update code here
</cfquery>
<cfelse>
it's empty. do nothing
</cfif>
2. If it IS running the update, but not changing the value then it means the database didn't find a record matching your criteria. So you need to find out why. Add a result attribute to the query and dump it to see the generated sql
<cfquery result="yourResult" ...>
Your update code here
</cfquery>
<cfdump var="#yourResult#">
ASKER
Here is my code. Please open it in dreamweaver... Do i'm missing anything ?
First name and last name are updating correctly...
only the CMTEE_PREF is not being update. thank you very much for your advice.
update-code.txt
First name and last name are updating correctly...
only the CMTEE_PREF is not being update. thank you very much for your advice.
update-code.txt
It's very hard to tell what's going on. But I would strongly recommend redesigning your form and query. The way it's designed now it runs a separate update for each field. That's extremely inefficient. It's also confusing and difficult to debug. It's better to update all fields in a single query.
<CFIF #FORM.LoginName# NEQ "">
Why are the fields empty to start with? Normally edit forms populate all form fields with the old values - so you don't have use all that <CFIF not empty logic>. You just update all fields
UPDATE users
SET Login = <cfqueryparam value="#FORM.LoginName#" cfsqltype="cf_sql_varchar" >
, ... rest of fields
As to why it's not updating, see my previous response where I explained the 2 mostly causes and how to debug them.
<CFIF #FORM.LoginName# NEQ "">
Why are the fields empty to start with? Normally edit forms populate all form fields with the old values - so you don't have use all that <CFIF not empty logic>. You just update all fields
UPDATE users
SET Login = <cfqueryparam value="#FORM.LoginName#" cfsqltype="cf_sql_varchar"
, ... rest of fields
As to why it's not updating, see my previous response where I explained the 2 mostly causes and how to debug them.
ASKER
okay i wil do the test. thanks.
ASKER
it didn't work :(
ASKER
it's not running the UPDATE code only at at users fields (loginname, firstname, lastname, password, into the users table. nothing on the dbo.cvitool.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Please review it like this you mean.
<CFQUERY NAME="UpdateInfo" datasource="Aies" username="#application.use rname#" password="#application.pas sword#">
<CFIF #FORM.user_id# NEQ "" OR #FORM.CMTEE_PREF# NEQ "">
<CFIF #FORM.CMTEE_PREF# NEQ "">
UPDATE c
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#" cfsqltype="cf_sql_varchar" >
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer" >
</CFIF>
</CFIF>
</CFQUERY>
<cfdump var="#yourResult#">
<cfelse>
empty. do nothing>
</cfif>
<CFQUERY NAME="UpdateInfo" datasource="Aies" username="#application.use
<CFIF #FORM.user_id# NEQ "" OR #FORM.CMTEE_PREF# NEQ "">
<CFIF #FORM.CMTEE_PREF# NEQ "">
UPDATE c
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#" cfsqltype="cf_sql_varchar"
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer"
</CFIF>
</CFIF>
</CFQUERY>
<cfdump var="#yourResult#">
<cfelse>
empty. do nothing>
</cfif>
No try it exactly like in my previous response. You want to test the query on a page by itself, without all the other stuff. Just fill in the cfquery datasource name and password here:
<cfquery result="yourResult" .... other settings ...> <=== here
<cfquery result="yourResult" .... other settings ...> <=== here
> <cfif len(trim(FORM.CMTEE_PREF)) >
Ignore the very last line, its' a copy paste error
Ignore the very last line, its' a copy paste error
ASKER
ok here what i have now.
<cfif len(trim(FORM.CMTEE_PREF)) >
running update query ...
<cfquery result="yourResult" datasource="Actuaries" username="#application.use rname#" password="#application.pas sword#">
UPDATE c
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#"
cfsqltype="cf_sql_varchar" >
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer" >
</cfquery>
<cfdump var="#yourResult#">
<cfelse>
empty. do nothing>
</cfif>
<cfif len(trim(FORM.CMTEE_PREF)) >
I got that error.
Just in time compilation error<P> An unknown attribute '<b>result</b>' has been encountered at document position (96:23) to (96:28) while processing tag CFQUERY. This tag can only take the following attributes: <ul><li>BLOCKFACTOR<li>CAC HEDAFTER<l i>CACHEDWI THIN<li>CO NNECTSTRIN G<li>DATAS OURCE<li>D BNAME<li>D BPOOL<li>D BSERVER<li >DBTYPE<li >DEBUG<li> MAXROWS<li >NAME<li>P ASSWORD<li >PROVIDER< li>PROVIDE RDSN<li>SQ L<li>TIMEO UT<li>USER NAME</ul>< p>The last successfully parsed CFML construct was a CFQUERY tag occupying document position (96:14) to (96:21).<p>The specific sequence of files included or processed is:<code><br><strong>d:\us ers\actca\ html\membe rs\toolkit \update_vo lunteer_in fo_ee.cfm </strong></code><P><P>
<cfif len(trim(FORM.CMTEE_PREF))
running update query ...
<cfquery result="yourResult" datasource="Actuaries" username="#application.use
UPDATE c
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#"
cfsqltype="cf_sql_varchar"
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer"
</cfquery>
<cfdump var="#yourResult#">
<cfelse>
empty. do nothing>
</cfif>
<cfif len(trim(FORM.CMTEE_PREF))
I got that error.
Just in time compilation error<P> An unknown attribute '<b>result</b>' has been encountered at document position (96:23) to (96:28) while processing tag CFQUERY. This tag can only take the following attributes: <ul><li>BLOCKFACTOR<li>CAC
"result" was added in CF8 so it won't work under older versions like CF7. If you're running an older version you'll have to enable debugging in the CF admin or do it the old fashioned way. Copy the SQL and cfoutput it before the actual query
ie
<cfoutput><strong>DEBUG</s trong> this is the sql generated<br>
UPDATE c
SET c.CMTEE_PREF = "#FORM.CMTEE_PREF#"
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = #client.user_id#
</cfoutput>
<cfquery ...>the actual UPDATE here </cfoutput>
ie
<cfoutput><strong>DEBUG</s
UPDATE c
SET c.CMTEE_PREF = "#FORM.CMTEE_PREF#"
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = #client.user_id#
</cfoutput>
<cfquery ...>the actual UPDATE here </cfoutput>
UPDATE c
SET c.CMTEE_PREF = <cfqueryparam value="#FORM.CMTEE_PREF#"
cfsqltype="cf_sql_varchar"
FROM users u INNER JOIN cvitool c ON u.id_number = cast(c.id as INT)
WHERE u.user_id = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer"
<CFIF #FORM.CMTEE_PREF# NEQ "">
Also to ignore all white space entries use trim()
<cfif len(trim(FORM.CMTEE_PREF))
the value is not empty. do the UPDATE
</cfif>