我正在做一个连接python和mysql的项目,当我运行代码时,它显示错误
输入:
import sys
import mysql.connector as sql
conn=sql.connect(host='localhost',user='root',password='1Chirumamilla$',database='medical_store')
c1=conn.cursor()
if conn.is_connected:
print(" WELCOME TO SAI MEDICAL STORE ")
print("1. Login")
print()
option=int(input("Enter your choice : "))
if option==1:
print()
user=input('User Name : ')
user=user.upper()
c1.execute("select * from account_details where User_Name like '" + user + "'")
datas=c1.fetchall()
for i in datas:
value_1=i[0]
value_2=i[1]
if user==value_1:
password=input('Password : ')
password=password.upper()
if password!=value_2:
print("INVALID PASSWORD")
print("RUN THE PROGRAM AGAIN")
sys.exit()
elif password==value_2:
print()
print('Login successful')
print()
def med():
print("SELECT THE OPTION")
print()
print("1.Customer's Account")
print("2.Medicine Cost")
print("3.Search Medicine Stock")
print("4.Search Customer")
print("5.Bill")
print("6.Add Medicines")
print("7.Search Employee Details")
print("8.Add or Delete Employee Details")
print()
option=int(input("Enter an option:"))
if option==1:
account_number=int(input("Enter customer's acct_number:"))
patient_name=input("Enter customer's name:")
age=int(input("Enter customer's age:"))
address=input("Enter customer's address:")
phone_number=int(input("Enter customer's mobile number:"))
balance_amount=float(input("Enter Amount Paid:"))
x="insert into customers_details values("+str(account_number)+",'"+patient_name+"',"+str(age)+",'"+address+"',"+str(phone_number)+","+str(balance_amount)+")"
c1.execute(x)
print("Account created")
conn.commit()
if option==2:
a=input("Enter the Medicine Name to show Price : ").upper()
f=int(input("Enter the Quantity : "))
c1.execute("select medicine_name,total_cost from medicines_details where medicine_name like '" + a + "'")
b=c1.fetchall()
for x in b:
print("Medicine Name : ",x[0])
print("Medicine Cost : ",x[1]*f)
if option==3:
Med=input("Enter Medicine name to search : ").upper().strip()
c1.execute("select medicine_name from medicines_details; " )
b = [i[0] for i in c1.fetchall()]
if Med in b :
print("Medicine is in stock")
else:
print("Medicine out of stock")
if option==4:
accnum=int(input("Enter the Customer's Account Number :"))
print("Customer Account Number, Customer name, Phone Numbers Are Given Below")
print()
c1.execute("select account_number, patient_name, phone_number from customers_details where account_number like "+str(accnum)+"")
c=c1.fetchall()
b = [i[0] for i in c1.fetchall()]
if b == accnum:
for x in c:
print("Account Number : " ,x[0])
print("Name : ",x[1])
print("Mobile Number : ",x[2])
print()
else:
print("Customer Details Dont exist")
print("Create A New Account")
if option==5:
patient_name=input("enter the patient_name :")
no=int(input('enter the number of medicine:'))
print('customer name:',patient_name)
for i in range (no):
med_name=input('enter medicine name : ')
c1.execute("select medicine_code,gst,sgst,total_cost from medicines_details where medicine_name like '" + str(med_name) +"'" )
data=c1.fetchall()
for row in data:
print('medicine_code of',med_name,':',row[0])
print('gst of',med_name,':',row[1])
print('sgst of',med_name,':',row[2])
print('cost_per_item of',med_name,':',row[3])
conn.commit()
account_number=input('enter account_number:')
c1.execute("select balance_amount from customers_details where account_number like'"+str(account_number)+"'")
datas=c1.fetchall()
datas=list(datas[0])
datas=datas[0]
print(datas)
conn.commit()
print("rows affected:",c1.rowcount)
conn.commit()
quantity=int(input("enter the quantity:"))
total_amount=row[3]*quantity
print("total_amount of",med_name,':',total_amount)
v_sql_insert="insert into SS_bill (medicine_name,medicine_code,gst,sgst,cost_per_item,quantity,amount_paid,amount_to_be_paid)values('{}',{},{},{},{},{},{},{})".format(med_name,row[0],row[1],row[2],row[3],quantity,datas,total_amount)
c1.execute(v_sql_insert)
conn.commit()
print("Records added")
if option == 6:
mednam=input("Enter the Name of the Medicine : ").upper()
medcod=int(input("Enter the 6 digit code : "))
medgst=float(input("Enter the GST on the Medicine : "))
sgmed=float(input("Enter the SGST on the Medicine : "))
medcos=float(input("Enter the price of the Medicine : "))
x="insert into medicines_details values('"+ mednam +"',"+ str(medcod) +","+ str(medgst) +","+ str(sgmed) +","+ str(medcos) +")"
c1.execute(x)
print("Medicine Added")
conn.commit()
if option == 7:
empid = int(input("Enter the Employee Id : "))
x="select employee_name, employee_id, designation, date_of_joining, salary from employees_details where employee_id like '"+ str(empid) +"'"
c1.execute(x)
c=c1.fetchall()
for x in c:
print("Employee Name : ",x[0] )
print("Customer Id : ",x[1])
print("Designation : ",x[2])
print("Year of Joining : ",x[3])
print("Salary : ",x[4])
if option == 8:
print("1.Add Employee")
print("2.Remove Employee")
print()
c=int(input("Choose the option to continue : "))
if c == 2:
a=input("Enter the Employee Id of the employee to remove : ")
x="delete from employees_details where employee_id like '"+ str(a) +"'"
c1.execute(x)
conn.commit()
print("Employee Removed")
if c == 1:
b=input("Enter the Employee Name to add : ")
e=int(input("Enter the Employee ID : "))
f=input("Enter the designation of the employee : ")
g=input("Enter the year of joining of the employee : ")
i=int(input("Enter the Salary of the Employee : "))
y="insert into employees_details values ('" +b+ "',"+str(e)+", '" +f+ "',"+str(g)+","+str(i)+")"
c1.execute(y)
conn.commit()
print("Employee Added")
restart=input("Do you want to continue? (YES/NO)").upper()
if restart == "YES":
med()
elif restart == "NO":
print("Thank You Visit Again")
sys.exit()
med()
if put accnum = 9989,它存在于mysql表中,但当我运行代码时,它显示该值不存在
输出:
Enter the Customer's Account Number :9989
Customer Account Number, Customer name, Phone Numbers Are Given Below
Customer Details Dont exist
Create A New Account
1条答案
按热度按时间ruoxqz4g1#
b==accnum
是一个列表(如本例中的[9989,9989,..]),而accnum
只是一个整型变量,因此无法将b==accnum
的值设为true。与
它将检查列表是否包含任意数量的具有给定帐号的记录,否则列表将为空,大小为零。