Okay... basically, I re-ran the script in index.php just to check, and only one row was inserted. This is after a computer reboot since yesterday, so it must have been a PHP/MySQL glitch. That's so infuriating since I spent ages trying to debug it.
Thanks anyway folks.
Glad you "fixed" it. Wish we had a better understanding of what was happening in order to detect/prevent future occurrences. Hopefully it was some really bizarre coincidence that is highly unlikely to recur.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation