Page 1 of 1

What is going on here? Mysql problems

Posted: Sun Jan 08, 2006 10:35 pm
by jaymoore_299
I have this code here that updates an entry, adds one to whatever site sent me a surfer

Code: Select all

$query="UPDATE traffic_in SET amount_ = amount_ + 1 WHERE referer_ = '$url' AND time_='$todaystime' AND unique_ = '$unique_'";
$result = mysql_query($query) or die(mysql_error());


When I run only the php script containing this code, then a single hit is registered.
However, when I include this in my main page and have that load, it's always 2 hits that are registered and I have no idea why.

Some possibilities here are:
- I included the script two times in the main page. (this was not the case)
- There are two entries for the specific referer so that when I incremented it by one, two of them were incremented and so two hits were counted
(also not the case)

I tried different numbers for the increment. When I put in 3 and just ran the script itself I had 3 hits registered. When I loaded my main page with the script then I had 6 hits registered. Any ideas on what could be causing this?

Posted: Sun Jan 08, 2006 10:58 pm
by feyd
how, file structure wise, is the code placed inside the overall code? If it's inside a function, is it possible you called it twice? How is today's time calculated? What type of field is the variable being tested against?

Posted: Sun Jan 08, 2006 10:59 pm
by josh
change it to include_once, also try echoing out some sort of debug. Another little thing that <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> me the @#% off and I just now thought if it (i had this same problem with a blog script months ago), maybe your error document is pointing to a php script? in that case your browser is requesting favicon.ico and it does not exist? try commenting the line out in the 404 document you are using.

Posted: Mon Jan 09, 2006 1:06 am
by jaymoore_299
I found the problem, though I don't understand it. Through the process of elimination I ended up with one line with something like background: url() in my stylesheet. Now I know I have a $url variable in my php script and that's probably what might cause some problems, but how can this statement cause the code to run twice? Basically this is what my page looks like

<?php
include 'in.php'
?>
<doctype
<html>
<style>
...
background: url()
</style>
....

The only section with php in it is on the top, everything else is html. How can something not inside <?php ?> cause this kind of error? Btw I am using firefox browser if it makes any difference.

Posted: Mon Jan 09, 2006 1:28 am
by feyd
url() causes the browser to request the page as if it was a image, in this case... So the page will be requested twice, once for the browser getting the page, and once for that background style setting.