muhammad_nasif

Untitled

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