What is going on here? Mysql problems

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

What is going on here? Mysql problems

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
Last edited by feyd on Sun Jan 08, 2006 11:00 pm, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply