Skip to content

Commit 1440857

Browse files
committed
Added functionality to add data to the sql table
1 parent 3d45535 commit 1440857

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

adminpanel.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import pickle
2-
import mysql.connector
31
import hireemployee
42

5-
def cursor():
6-
cred = open("cred.dat","rb")
7-
dat=pickle.load(cred)
8-
cred.close()
9-
Passwo=dat[0]
10-
Databa=dat[1]
11-
query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
12-
return query.cursor()
133

144
def ap2():
155
print("ap2")

hireemployee.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
from datetime import date
2+
import pickle
3+
import mysql.connector
4+
25
def age(birthdate):
36
today = date.today()
47
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
58
return age
69

10+
cred = open("cred.dat","rb")
11+
dat=pickle.load(cred)
12+
cred.close()
13+
Passwo=dat[0]
14+
Databa=dat[1]
15+
query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
16+
cur=query.cursor()
17+
718
def ap1():
819
print("-------------Hire Employee Process-------------")
920

@@ -152,11 +163,17 @@ def ap1():
152163

153164

154165
print("=========== Final Data ===========")
155-
x=(emp_no,
156-
birth_date,
157-
first_name,
158-
last_name,
159-
gender,
160-
hire_date)
161-
print(x)
162-
return x
166+
print(emp_no,birth_date,first_name,last_name,gender,hire_date)
167+
add_employee=("INSERT INTO employees "
168+
"(emp_no,birth_date,first_name,last_name,gender,hire_date) "
169+
"VALUES (%s,%s,%s,%s,%s,%s)")
170+
data_employee=(emp_no,birth_date,first_name,last_name,gender,hire_date)
171+
try:
172+
cur.execute(add_employee, data_employee)
173+
query.commit()
174+
cur.close()
175+
query.close()
176+
except mysql.connector.Error as err:
177+
print(err.msg())
178+
else:
179+
print("Values added successfully!!")

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import setup
2-
def getconnection():
3-
return setup.setup()
2+
import accounttype
3+
conn=setup.setup()
4+
accounttype.acctype()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def querycheck():
127127
print("already exists.")
128128
existing+=1
129129
else:
130-
print(err.msg)
130+
print(err.msg())
131131
else:
132132
print("OK")
133133
with open("firsttime.txt","w") as f:

0 commit comments

Comments
 (0)