/    Sign up×
Community /Pin to ProfileBookmark

Very strange MySQL or Firefox problem

I use this piece of code to update the number of views a file has received.

[code=php]
/* Update views. */
$sql_update = “UPDATE dukkie_script SET views = views + 1 WHERE file = ‘” . $_GET[‘file’] . “‘”;
@mysql_query ($sql_update);
[/code]

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 ([url]http://www.mywebsite.com/viewfile/viewsource/testfile[/url])
a .htaccess rewrites the link to:
[url]http://www.mywebsite.com/index.php?url=viewfile&view=source&file=testfile[/url]

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:

[code=php]
if (file_exists (“/path/to/file/” . $_GET[‘file’]))
{
// update page and use highlight_file () to view the source of $_GET[‘file;’]
}
[/code]

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.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanAug 30.2004 — 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
Copy linkTweet thisAlerts:
@redijediAug 30.2004 — Sounds odd. Make sure that your browsers aren't caching an older in-development script.

Shouldn't be the browser though.
Copy linkTweet thisAlerts:
@Bootsman123authorAug 30.2004 — 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:
[code=php]
<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 ();
?>
[/code]
Copy linkTweet thisAlerts:
@MstrBobAug 30.2004 — When I access that page with Firefox, it doesn't increase by two...
Copy linkTweet thisAlerts:
@Bootsman123authorAug 30.2004 — I said this worked fine ?, but with this working I even less ideas on what the problem can be in the other pages.
×

Success!

Help @Bootsman123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...