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.