Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple ColdFusion script works in IE but not Firefox?

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?!

like image 277
Gary Stanton Avatar asked Dec 30 '22 10:12

Gary Stanton


2 Answers

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.

like image 58
Re0sless Avatar answered Jan 02 '23 10:01

Re0sless


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.

like image 22
Gary Stanton Avatar answered Jan 02 '23 10:01

Gary Stanton