I am not entirely sure this is possible, so would like clarification if it is and if so what is the way forward (to prevent or if not possible to mitigate).
I have a PHP script which allows user submitted data (which does an INSERT INTO) and another PHP script (different file) which allows the deletion of said data (which does a DELETE FROM), now lets say I was deleting stuff and there happens to be someone submitting some stuff at the same time - could this lead to data being overlooked (remaining in that table)?
I have searched and come across stuff relating to race conditions - unsure if this is exactly what the above issue would be classed as?
If it helps to put the above into the context, the user has the ability to submit replies (posts) to a topic (which does an INSERT INTO forum_posts WHERE topic_id = ?) and I have the ability to delete the topic (which should hopefully delete all attached posts) i.e. DELETE FROM forum_topics WHERE topic_id = ? and then DELETE FROM forum_posts WHERE topic_id = ?, if when doing the deletion a user was to somehow be able to post a reply to the topic, then this could cause issues (as we have a post which exists with no topic!).
Hope this makes sense.
This is exactly what transactions are made for. For example (pseudo-code)
$db->beginTransaction();
// A set of queries; if one fails, an exception should be thrown
$db->query('first query');
$db->query('second query');
$db->query('third query');
// If we arrive here, it means that no exception was thrown
// i.e. no query has failed, and we can commit the transaction
$db->commit();
When you do the commit
all 3 transactions are done simultaneously w/o delay, and will not be interrupted by some other user deleting something