This code is not going to change the processing of the order, it is only going to help us find the cause of the problem.
basically the idea is to find each occurrence of "cart.php" on the confirm page and the success page and add a unique query string variable, this way when you are directed to the cart page, you can tell which line of code was responsible for sending you there.
the line "header("Location: cart.php");" is not on the success page, you should look for it on the confirm page.
after you make the changes as I directed above, when you get redirected to the cart page, let me know the address in the address bar including the query string, this will tell me which line of code was responsible for the redirect.