views:

937

answers:

6

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

+3  A: 

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.

Re0sless
Right you are... I added a last updated field and it did indeed make a change... but I'm not aware of FF hitting the script twice, and can't see why it would... any ideas how to stop that happening?
Gary
I've seen an obscure issue in FF before when it stumbles across a character it doesn't recognise and needs to re-display the page in a different char-set, and will resubmit the page to do so. You don't have any strange chars that differ wildly from your declared doctype?
ConroyP
Hmmmmmmmmmm..... not that I'm aware of... I use the £ symbol on the resulting page, which I've had problems with in the past... but not on the page that actually makes the database calls... even if it re-displayed the results page, that shouldn't cause a problem.
Gary
Is the request to the script that changes the status a GET or POST? if its a GET try changing it to a POST, and see if that helps. I had problems displaying £ in the past so i use £ ( now.
Re0sless
It's not a form, it's just a page... (so a get, right?) the page takes the record ID from the URL, calls the CF function to change the record, then uses CFLOCATION to go back to the record list page.
Gary
see my update, and yes its a get if it comes from the url.
Re0sless
A: 

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" />;
Ed Bartram
I tried this, but it didn't make any difference.
Gary
+2  A: 

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>
Al Everett
I have to agree -- There's no way in H-E-Double Hockey Sticks that the browser is affecting the server side code. You've either got a caching issue, or something to do with the form or links that are starting this process.
Adam Tuttle
I agree too. If it was a server-side issue, I'm pretty sure I could have figured it out. I don't get what FireFox is doing to run this code twice.The tangent's a great idea, thanks... however the code you posted doesn't quite work - should read: #val(1 - Arguments.qGetProductAttribute.bActive)#
Gary
+2  A: 

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.

Brian Sadler
The queries are definitely getting called, it just seems they're being called twice.The database's 'last updted' field is being updated.
Gary
+3  A: 

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.

Gary
A: 

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.