“Duplicate Entry For Key…” I had this error come out of nowhere, and if you tried to create a comic, sorry! I didn’t realize this was the mistake, and took ~ 2 months off from working on things. The website is back on its feet though, and I’m working on finalizing the release that is just about 95% done. I don’t have much experience using MySQL or any relational database for that matter. Taketoon is my first dynamic website that I’ve actually programmed myself, so I’ve made, and will make, many more mistakes.
The Problem:
$sql= “INSERT INTO table”;
$sql .= “(data1,data2,data3,data4) “;
$sql.= “VALUES (‘{$this->variable1}’,'{$this->variable2}’,'{$this->variable3}’,'{$this->variable4}’)”;
mysqli_query($this->dbConnection,$insertSQL) or die(mysqli_error($this->dbConnection))
The Error:
“Duplicate Entry For Key…” blah blah blah.
I *think* what happened is somehow an insert was interrupted and screwed up the table. Then each subsequent insert tried to use the corrupt id which was already in use.
The Fix:
$sql= “INSERT IGNORE INTO table”;
$sql .= “(data1,data2,data3,data4) “;
$sql.= “VALUES (‘{$this->variable1}’,'{$this->variable2}’,'{$this->variable3}’,'{$this->variable4}’)”;
mysqli_query($this->dbConnection,$insertSQL) or die(mysqli_error($this->dbConnection))
Commentary:
Tested it out, and it seems to be working. One of these days I need to move off shared hosting and actually give the website a chance, but for now I have to stick with MyISAM tables (can’t use InnoDB in my enviroment) and I have a bad feeling that MyISAM had something to do with it.
Please excuse my rambling:
I really didn’t like taking a break from working on taketoon, but I had too. I was completely burned out, and after learning the languages, and working on the site for over a year and a half, I needed some time to clear my mind. I took up guitar and got alot more exercise, but the good news is….*drum roll please* is that I’m refreshed and really excited to churn out some great content.
In the time I’ve spent away from taketoon, I’ve realized just how many mistakes I’ve made. The UI is still rough, which is admittly, the hardest part for me to grasp. Since I work on software each and every day, I really need to get my skills up in astetics and presentation. I’ve kinda taken the approach that it doesn’t matter, but the fact is, it is the only thing that matters. It needs to look good AND it needs to work well, and I feel like I’ve only achieved half of that goal (at best).
Anyway, the site is working again, and my deepest apologies to the people kind enough to use the website only to get an error when they tried to submit.