Jump to content

+1 = +2?


NLCJ

Recommended Posts

Hello,

I know that the title might be a bit confusing, but I've got a problem. When I say that it has to do +1 it does +2. The code I use is located at the top of the page:

$d_websitestatistics = mysql_fetch_array(mysql_query("SELECT * FROM websites WHERE id='".mysql_real_escape_string($_COOKIE['websiteid'])."'"));
$views = $d_websitestatistics['views'];
$newviews = $views+1;
echo "UPDATE websites SET views='".$newviews."' WHERE id='".mysql_real_escape_string($_COOKIE['websiteid'])."'<br />".$d_websitestatistics['views']."<br />".$newviews;

$newviews is $d_websitestatistics + 2, even though I said it should only add 1. What is the problem?

 

Regards,

NLCJ

Link to comment
Share on other sites

I think my server didn't pass its math test... It WORKED using:

mysql_query("UPDATE websites SET views= views + 1 WHERE id='".mysql_real_escape_string($_COOKIE['websiteid'])."'");

But now it also adds 2 to the value... What is going on?!

 

Regards,

 

Link to comment
Share on other sites

This might be useful, I don't know. If I use:

mysql_query("UPDATE websites SET views= views + 0.5 WHERE id='".mysql_real_escape_string($_COOKIE['websiteid'])."'");

it adds ALSO 2 to the value.

 

And using:

mysql_query("UPDATE websites SET views= views + 5 WHERE id='".mysql_real_escape_string($_COOKIE['websiteid'])."'");

results in adding 10 to the database. Double entries isn't a possibility since I only edited one line...

 

I'm totally confused! :S

Link to comment
Share on other sites

Thanks, I think that is the reason. I'm using FancyBox to load that page, the strange thing is that when a cookie exists it shouldn't update the value. If a cookie doesn't exist it will update the value, and directly set a cookie (this means that if the page reloads it won't update the values?). I'm going to Google about it! :) Thanks!

Link to comment
Share on other sites

I have not heard of any cases where Chrome will request a page twice, but either your browser (due to debugging tools or to apply default character encoding), some javascript in your browser (typically some validation logic submitting a form and the actual form being submitted by the browser), your web server (if you are rewriting the url and/or some cases of an add on domain), or your logic on the server is causing this.

Link to comment
Share on other sites

(typically some validation logic submitting a form and the actual form being submitted by the browser)

 

I thought this was the problem, since the form was submitting to that page and the javascript was opening that page in the FancyBox. Though the problem persists, even after removing the total 'action=' part...

 

I've checked it, and the php file is only requested once in the whole script.

Link to comment
Share on other sites

You can typically use a session variable to prevent duplicate page requests. Set a session variable at the point where the first page request has successfully been processed and at the start of the page check if the session variable is already set and skip processing the page if it is set.

Link to comment
Share on other sites

You can typically use a session variable to prevent duplicate page requests. Set a session variable at the point where the first page request has successfully been processed and at the start of the page check if the session variable is already set and skip processing the page if it is set.

 

I guess it still isn't the problem. If I've set it using sessions it shows a white page, and if you close the FancyBox and reopen it it shows the processed page. Even though it still adds 2 to the value! Strange...  :confused:

Link to comment
Share on other sites

I give up... All solutions offered here will be tried (if someone feels like notifying me about another solution).

 

How do I fix it?

Simple:

I created a HTML file which refreshes after 3 seconds to the other (PHP) file, then everything will be fine...

 

Regards and thanks,

NLCJ

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.