Advertisement
abrar1

Untitled

Dec 11th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. if request.method == "POST" and 'Click' in request.POST:
  2. if request.method == "POST" and 'Click' in request.POST:
  3. print("ID is : ")
  4. print(id)
  5. name = request.POST['name']
  6. designation = request.POST['designation']
  7. salary = request.POST['salary']
  8. password = request.POST['password']
  9. username = request.POST['username']
  10.  
  11. #
  12. branch = request.POST['branch']
  13. branch_no = ""
  14. if branch :
  15. branch_no = branch[len(branch) - 1]
  16. #
  17. hashed_password = hashlib.md5(password.encode('utf-8')).hexdigest()
  18.  
  19. if not branch_no:
  20. sql = "SELECT BRANCH_ID FROM BRANCH_EMPLOYEE WHERE EMPLOYEE_ID = %s"
  21. cursor = connection.cursor()
  22. cursor.execute(sql, [id])
  23. result = cursor.fetchall()
  24. cursor.close()
  25. name = result[0][0]
  26.  
  27. if not name:
  28. sql = "SELECT NAME FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
  29. cursor = connection.cursor()
  30. cursor.execute(sql, [id])
  31. result = cursor.fetchall()
  32. cursor.close()
  33. name = result[0][0]
  34. if not designation:
  35. sql = "SELECT DESIGNATION FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
  36. cursor = connection.cursor()
  37. cursor.execute(sql, [id])
  38. result = cursor.fetchall()
  39. cursor.close()
  40. designation = result[0][0]
  41. if not salary:
  42. sql = "SELECT SALARY FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
  43. cursor = connection.cursor()
  44. cursor.execute(sql, [id])
  45. result = cursor.fetchall()
  46. cursor.close()
  47. salary = result[0][0]
  48. if not password:
  49. sql = "SELECT PASSWORD FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
  50. cursor = connection.cursor()
  51. cursor.execute(sql, [id])
  52. result = cursor.fetchall()
  53. cursor.close()
  54. hashed_password = result[0][0]
  55. if not username:
  56. sql = "SELECT USERNAME FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
  57. cursor = connection.cursor()
  58. cursor.execute(sql, [id])
  59. result = cursor.fetchall()
  60. cursor.close()
  61. username = result[0][0]
  62.  
  63. cursor = connection.cursor()
  64. print([name, designation, salary, username, hashed_password, id])
  65.  
  66. sql = "UPDATE EMPLOYEES SET NAME = '" + name + "',DESIGNATION = '" + designation + "' ,SALARY = " \
  67. + salary + " ,USERNAME='" + username + "' ,PASSWORD='" + hashed_password + "' WHERE EMPLOYEE_ID=" + str(
  68. id)
  69.  
  70. cursor.execute(sql)
  71. connection.commit()
  72. cursor.close()
  73.  
  74. cursor = connection.cursor()
  75. print(branch_no)
  76. sql = "UPDATE BRANCH_EMPLOYEE SET BRANCH_ID = %s WHERE EMPLOYEE_ID = %s"
  77. cursor.execute(sql,[branch_no, id])
  78. connection.commit()
  79. cursor.close()
  80. return redirect(show_employees)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement