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?!
Are you 100% certain that the database record does not change? You could get this affect if firefox calls you script twice, once before the page is rendered and once after.
So the product gets set to disabled, then after the page is sent to the browser it is updated again (and as it is already disabled, it is re-enabled).
If you have add a last update field to the database and update that every time your product is amended then you would be able to tell if this is the case.
EDIT: responding to the comments below, a quick + dirty fix would be to check the last update time stamp first and if its with in n seconds of the current time dismiss the update.
Do you have any plug-ins in firefox that maybe re-calling the page? perhaps for dev purposes? an easy test to see if its your script or a quirk in firefox would be to change your get url to a form with a post method, as the browser/ plug-in shouldn't re-call a post request.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With