Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function insert_emp_pdo() {
- global $con;
- if (isset($_POST['insert_post'])) {
- $fname = $_POST['first_name'];
- $lname = $_POST['last_name'];
- $email = $_POST['email'];
- $type = $_POST['type'];
- $username = $_POST['username'];
- $password = $_POST['password'];
- if ($fname == '' || $lname == '' || $email == '' || $type == '' || $username == '' || $password == '' ) {
- echo 'please fill all values';
- } else {
- try {
- // First of all, let's begin a transaction
- $con->beginTransaction();
- // A set of queries; if one fails, an exception should be thrown
- $con->query('INSERT INTO users (username, password) VALUES ('$user', '$pass')');
- $con->query('INSERT INTO employee (fname, lname, email, type, user_id) VALUES ('$fname', '$lname', '$email', '$type', LAST_INSERT_ID())');
- // If we arrive here, it means that no exception was thrown
- // i.e. no query has failed, and we can commit the transaction
- $con->commit();
- } catch (Exception $e) {
- // An exception has been thrown
- // We must rollback the transaction
- $con->rollback();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment