Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

The code you've posted isn't the cause of the error because it's all server side code - there's nothing happening on the client in there.

I'd turn on CF debugging (including database activity) and stick a tag right after the closing tag, and before any redirection back to the product view page. Run the code and look at the SQL debug output.

My guess is that when using Firefox the block of code containing the queries just doesn't get called.

This may be a browser caching issue. There's no way that straight CF code could be affected by the browser being used. What happens if you refresh the page where you're displaying the products? You also need to look at the database directly to see if the value is changing or not.

On a bit of a tangent, you can eliminate the need for an if statement at all with a little simple math.

<cfquery name="qChangeStatus" datasource="#Request.sDSN#">
    UPDATE  tblProductAttributes
    SET
         bActive = <cfqueryparam value="#val(1 - Arguments.qGetProductAttribute.bActive)#" cfsqltype="CF_SQL_INTEGER" maxlength="1" />
    WHERE   
        iProductAttributeID = <cfqueryparam value="#Arguments.iProductAttributeID#" cfsqltype="CF_SQL_INTEGER" />;
</cfquery>

Try removing the semi-colon at the end of your WHERE clauses in your SQL code.

WHERE   iProductAttributeID = <cfqueryparam value="#Arguments.iProductAttributeID#" cfsqltype="CF_SQL_INTEGER" />;

all those different answers, and none of them worked for me. I had to go to another forum where someone said it was the Skype Extension Addon in Firefox which causes ColdFusion databases to go crazy or not function. I uninstalled the Skype extension (thank you, Skype) and everything was back to normal. Hope this works for someone else too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top