I have searched and an IF statement seems to be the only way
The only thing is,when i put IF statement in - it doesn't seem to DO the INSERT statement at all, so nothing is being inserted, it's as if it's stopping before insert statement. As you can see $inserted is declared outside the loop and then changed to true inside so it stops, but it doesn't seem to be doing that.
Without it, it will loop each time the page is refreshed and insert into the database each refresh of the page, although i only need the INSERT statement to run once. I need it in the loop as that's where the information for the insert is.