This is the code I'm using to insert a record. Whenever an insert error occurs, does the autostart number of the subscriber table increase anyway, even when I roll back? What is the problem? I just want the auto increment number not to be added when an error occurs . Many thanks for the help.
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); $conn->beginTransaction(); try { $email = $_POST['Email']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $query="INSERT INTO subscriber (Email,FirstName,LastName,CreateDate) VALUES (?,?,?,CURDATE())"; $stmt = $conn->prepare($query); $stmt->bindParam(1, $email , PDO::PARAM_STR); $stmt->bindParam(2, $FirstName, PDO::PARAM_STR); $stmt->bindParam(3, $LastName, PDO::PARAM_STR); $stmt->execute(); $conn->commit(); } catch(PDOException $e) { $conn->rollBack(); die ($e->getMessage()."<a href='addSub.php'>Back</a>"); } $conn->beginTransaction(); try { $userID = $_SESSION['username']; $query="INSERT INTO list_sub (SubID,ListID) VALUES ('',$_SESSION[ListID])"; $stmt = $conn->prepare($query); $stmt->execute(); $conn->commit(); } catch(PDOException $e) { $conn->rollBack(); die ($e->getMessage()."<a href='addSub.php'>Back</a>"); } $conn = null;}
source share