Like bastien says, you need to use a table handler which has transactions. InnoDB is the most commonly used one.
You need a sensible scheme for ensuring that commit / rollback is done correctly. Your best bet is to ensure that every action which can modify data has a call to some sort of "finished" function at the end of it, which commits the transaction.
Otherwise, you will want to rollback the transaction- you can use register_shutdown_function to do this and/or write an error/exception handler which will automatically rollback in the event of an error.
Bear in mind that the biggest problem is that some actions (e.g. sending mail, interacting with third party systems via RPC) cannot be rolled back, so will still happen even in the event of an error causing a rollback - but there may then be no record of that action in your own database because it was rolled back.
Mark