I have a very simple bit of script that changes the status of an item in a MySql database – it works fine in IE7, but if I try it in Firefox, it looks like it’s worked, but hasn’t… Which is extremely odd.
The code is very simple – first I get the details of the record I’m looking for:
<cfscript> // Get the Product Attribute details Arguments.qGetProductAttribute = Application.cfcProducts.getProductAttributes(Arguments.iProductAttributeID); </cfscript>
This is working fine, if I dump the results, it’s just the content of the record as expected. So then I use an if statement to change the ‘active’ field from one to zero or vice versa.
<!--- If Product Attribute is active, mark as inactive ---> <cfif Arguments.qGetProductAttribute.bActive EQ 0> <cfquery name='qChangeStatus' datasource='#Request.sDSN#'> UPDATE tblProductAttributes SET bActive = <cfqueryparam value='1' cfsqltype='CF_SQL_INTEGER' maxlength='1' /> WHERE iProductAttributeID = <cfqueryparam value='#Arguments.iProductAttributeID#' cfsqltype='CF_SQL_INTEGER' />; </cfquery> <!--- Else if Product Attribute is inactive, mark as active ---> <cfelseif Arguments.qGetProductAttribute.bActive EQ 1> <cfquery name='qChangeStatus' datasource='#Request.sDSN#'> UPDATE tblProductAttributes SET bActive = <cfqueryparam value='0' cfsqltype='CF_SQL_INTEGER' maxlength='1' /> WHERE iProductAttributeID = <cfqueryparam value='#Arguments.iProductAttributeID#' cfsqltype='CF_SQL_INTEGER' />; </cfquery> </cfif>
I can’t see any reason whatsoever for this not to work… and indeed, in IE7 it works perfectly…
What happens is after this script is run, the browser goes back to the page that displays all of these records. For each record if the ‘bActive’ field is set to ‘1’, it will display the word ‘Active’ and if it’s set to ‘zero’, it will display ‘Disabled’. Simple enough.
If I run the script to disable a record, Firefox actually displays the word ‘disabled’ as expected, but the database record doesn’t change!
I’m at a loss… how can server-side code work fine in one browser and not in another?!
I found the cause of the problem… Firebug.
I haven’t the slightest idea what Firebug thinks it’s doing, if I remove the ‘cflocation’ tag from the script (the one that takes the user back to the summary page), then it works fine. But if I keep it in, Firebug seems to run the function again before forwarding the browser to the summary page.
There’s no reason for it to be doing this. Un-bloody-belivable.
At least it won’t be happening on the clients’ machines.