2
First you need InnoDB type tables in MySQL and not the regular ISAM.
You specify in the query START TRANSACTION; to start a transaction.
Then you do other operations with queries as INSERT, UPDATE, DELETE, etc.
If one fails do a query with ROLLBACK; and all operations after the transaction start become undone.
If all went good do a query with COMMIT;