Click to See Complete Forum and Search --> : Very strange MySQL or Firefox problem


Bootsman123
08-30-2004, 04:41 PM
I use this piece of code to update the number of views a file has received.


/* Update views. */
$sql_update = "UPDATE dukkie_script SET views = views + 1 WHERE file = '" . $_GET['file'] . "'";
@mysql_query ($sql_update);


When viewing this page in IE or Opera everything is fine and with every click the number of views is updated by one, but when viewing the page in Firefox the number of views is updated by two for every click.

I'll give some more info about how the page is included since I doubt anyone would know a fix for this problem.

When someone clicks a link (http://www.mywebsite.com/viewfile/viewsource/testfile)
a .htaccess rewrites the link to:
http://www.mywebsite.com/index.php?url=viewfile&view=source&file=testfile

using this RewriteRule:
RewriteRule ^viewfile/viewsource/([0-9a-zA-Z-]+)/?$ index.php?url=viewfile&view=source&file=$1

Then the index.php includes viewfile.php and with a simple if ($_GET['view'] == "source") the script knows that is has to print out the source of the file. Then if the file exists:

if (file_exists ("/path/to/file/" . $_GET['file']))
{
// update page and use highlight_file () to view the source of $_GET['file;']
}


Everything works fine, but the only problem I have is that in Firefox a view gets updated twice. I'm thinking of a bug, but maybe I've done something really dumb. So any help is welcome.

sciguyryan
08-30-2004, 04:55 PM
I don't think it can be a Client Side Problem as this is a Server Side script.


This is a very odd problem.


RyanJ

redijedi
08-30-2004, 05:49 PM
Sounds odd. Make sure that your browsers aren't caching an older in-development script.

Shouldn't be the browser though.

Bootsman123
08-30-2004, 06:27 PM
I cleared the cache, but I still have the problem. And I do agree that it's very strange it only occures with Firefox. I've created a test page:
http://test.dukkie.nl/test_views.php

and everything works fine so I think something is wrong with my other pages.

I used this testing code btw:

<a href="test_views.php">Reload this page</a>
<br /><br />

<?php
/* Establish a connection with the db. */
include ("db_connect.php");

/* Get the number of views from the db. */
$sql_query = "SELECT views FROM dukkie_test WHERE id = 1";
$sql_views = @mysql_result (@mysql_query ($sql_query), 0, 0);

echo "<b>Number of views:</b> $sql_views";

/* Update the number of views. */
$sql_update = "UPDATE dukkie_test SET views = views + 1 WHERE id = 1";
@mysql_query ($sql_update);

/* Close connection with the db. */
@mysql_close ();
?>

MstrBob
08-30-2004, 06:34 PM
When I access that page with Firefox, it doesn't increase by two...

Bootsman123
08-30-2004, 06:42 PM
I said this worked fine ;), but with this working I even less ideas on what the problem can be in the other pages.