Why is my MySQL being written to twice with only one code line?

Discussion in 'Programming' started by Glenn, Feb 17, 2014.

to remove all ads.
  1. Glenn

    Glenn Member

    Messages:
    189
    I have in my code,
    mysql_query("INSERT INTO 80sMusicLibraryUserNumPageVisits (userNum, date, page) VALUES ('$userNum', '$dateToday', '$newUrl')");

    It will write a record of:
    1 2014-02-16 1980
    wich would be correct. I'm user 1 because I was the first on the site. Date and page is also correct. But, it will follow with a record of:
    1 2014-02-16 missing.html

    Why is it doing this??
    It does it every time. I even went to the site on my phone and it did the same thing.

    This is the only query to this table. It is not in a loop. It is not in a function.

    Where did the value "missing.html" come from, and how could the $newUrl variable be set to that? I have no page called that.
     
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,611
    Probably because you do not catch errors and it is running on a HTTP: 404 error as well.
     
  3. Glenn

    Glenn Member

    Messages:
    189
    What exactly does that mean and how do I fix it?
     
  4. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,611
    "missing.html" is a common name used by some sitebuilder and content management systems for the "Page not found" URL.

    How do you fix it???

    Absolutely no idea I'm just a programmer not a clairvoyant.
     
  5. Glenn

    Glenn Member

    Messages:
    189
    I'm the "sitebuilder". I built it all by my written code.
     
  6. Glenn

    Glenn Member

    Messages:
    189
    I just now changed the code to:

    if ($userNum != 1) {
    mysql_query("INSERT INTO 80sMusicLibraryUserNumPageVisits (userNum, time, date, page) VALUES ('$userNum', '$time', '$dateToday', '$newUrl')");
    }

    and it created a new $userNum and recorded a page visit by that new userNum to each page I went to.
     
  7. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,611
    The SQL code is of ABSOLUTELY no use at all to even GUESS at what the PHP code is doing, or NOT as the case maybe.
     

Share This Page