Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8969333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:37+00:00 2026-06-15T17:34:37+00:00

Someone asked to fix an error in a database created a few years ago

  • 0

Someone asked to fix an error in a database created a few years ago using a custom CMS. I am still mainly a frontend guy but I am getting more and more into these kind of projects and try to learn, The error shown now is

 Fatal error: Duplicate entry '2012-12-10-1' for key 'PRIMARY' INSERT INTO stats SET pageID = '1', date = NOW(), visits = 1, views = 1 in /home/site/domains/domain.nl/public_html/cms/inc/functions.inc.php on line 10

What is odd is the date which seems to have two months in it. I understand a stat was being added to the stat database and that it was a duplicate of another. I just cannot find this entry in the table using PHPMyAdmin. I tried repairing the table, but that did not help. The error is fired off by this function in functions.inc.php:

function executeQuery($query) {
    global $website;
    static $count;
    benchmark("mysql", "start");
    if ($query == "count") {
        return $count;
    }
    $count++;
    $result = mysql_query($query, $website->DBConnection) or trigger_error("\n" . mysql_error() . "\n" . $query, E_USER_ERROR);
    $time += (microtime(true) - $tmp);
    benchmark("mysql", "stop");
    return $result;
}

The function on the Page.class.php is:

public function updateStats() {
        $result = executeQuery("SELECT count(*) FROM stats WHERE pageID = '" . $this->id . "' AND date = NOW()");
        $firstTime = mysql_result($result, 0) == 0;

        if ($firstTime) { // First time today someone visit this page
            executeQuery("INSERT INTO stats SET pageID = '" . $this->id . "', date = NOW(), visits = 1, views = 1");
            $_SESSION["stats"][$this->id] = true;
        } else {
            if (!$_SESSION["stats"][$this->id]) { // First time today this person visit this page
                executeQuery("UPDATE stats SET visits = visits + 1, views = views + 1 WHERE pageID = '" . $this->id . "' AND date = NOW()");
                $_SESSION["stats"][$this->id] = true;
            } else { // Second or more time someone visit this page.
                executeQuery("UPDATE stats SET views = views + 1 WHERE pageID = '" . $this->id . "' AND date = NOW()");
            }
        }
    }

Since that error the site seems to have been down.. I do not see any stats entered after 2012-10-04 . How can such a date be created, called DUPLICATE and how can I remedy this? Any help is appreciated.

As requested by @Roman Newaza

SHOW CREATE TABLE stats
stats   CREATE TABLE `stats` (
 `date` date NOT NULL DEFAULT '0000-00-00',
 `views` int(11) NOT NULL DEFAULT '0',
 `visits` int(11) NOT NULL DEFAULT '0',
 `pageID` int(11) NOT NULL DEFAULT '0',
 PRIMARY KEY (`date`,`pageID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:34:38+00:00Added an answer on June 15, 2026 at 5:34 pm

    When you have a compound primary key, the duplicate entry error message are formatted with a dash separator, like X-Y, where X is the value in one column and Y is the value in a second column.

    It’s just a coincidence in this case that the default date format also has dashes in it.

    INSERT INTO stats SET pageID = '1', date = NOW(), visits = 1, views = 1
    

    So you are setting the date column to NOW() which is ‘2012-12-10’ and a second integer column (I’m guessing pageID) with value ‘1’. The combination of these two values is already in the table, and that’s what’s violating the primary key. I infer from this that your table definition is something like:

    CREATE TABLE stats (
      `date` DATE NOT NULL,
      `pageID` INT NOT NULL,
      `visits` INT NOT NULL,
      `views` INT NOT NULL,
      -- possibly more columns
      PRIMARY KEY (`date`, `pageID`)
    );
    

    As for why you don’t see any data after 2012-12-04, I can guess that the duplicate key error caused the transaction to be rolled back, so both the entry that caused the error and the row that it conflicted with were undone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Someone asked a question a few moments ago that got recalled because it was
Years ago someone asked why c# doesn't allow incremental compilation like Java . El
Someone asked me to design a database and implement it using MySQL. Additionally, I
A few months ago I put together a site using Wordpress for a friend,
Over a year ago someone asked this question: Execute .sql files that are used
On a recent question about MVC attributes, someone asked whether using HttpPost and HttpDelete
It's been more than two years since someone asked Which SOAP XML object serialization
Someone asked a similar question before , getting the following error when I run
In a recent question, someone asked if they could make a time just using
Someone asked me about this and after reading some big O stuff I still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.