Guest User

Untitled

a guest
Nov 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function insert_emp_pdo() {
  2. global $con;
  3. if (isset($_POST['insert_post'])) {
  4. $fname = $_POST['first_name'];
  5. $lname = $_POST['last_name'];
  6. $email = $_POST['email'];
  7. $type = $_POST['type'];
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. if ($fname == '' || $lname == '' || $email == '' || $type == '' || $username == '' || $password == '' ) {
  12. echo 'please fill all values';
  13. } else {
  14. try {
  15. // First of all, let's begin a transaction
  16. $con->beginTransaction();
  17. // A set of queries; if one fails, an exception should be thrown
  18. $con->query('INSERT INTO users (username, password) VALUES ('$user', '$pass')');
  19. $con->query('INSERT INTO employee (fname, lname, email, type, user_id) VALUES ('$fname', '$lname', '$email', '$type', LAST_INSERT_ID())');
  20.  
  21. // If we arrive here, it means that no exception was thrown
  22. // i.e. no query has failed, and we can commit the transaction
  23. $con->commit();
  24. } catch (Exception $e) {
  25. // An exception has been thrown
  26. // We must rollback the transaction
  27.  
  28. $con->rollback();
  29. }
  30. }
  31. }
  32.  
  33. }
Add Comment
Please, Sign In to add comment