import mysql.connector as myc
from mysql.connector import Error
def new():
idtype=input("Type of Id proof present=")
idno=input("Identification number=")
name=input("Name of patient=")
age=input("Age=")
sex=input("Sex=")
address=input("Address=")
contactno=int(input("Contact Number="))
date=input("Date =")
doccons=input("Doctor consulted=")
reason=input("Consultation reason=")
dept=input("Department of doctor consulted=")
aller=input("Medical Allergies (if any)=")
insu=input("Availing Insurance=")
temp=input("Temperature of patient(degree celsius)=")
fees=int(input("Fees="))
if True:
db = myc.connect(host='localhost',
database='patients',
user='root',
password='root')
mc = db.cursor()
query = """INSERT INTO patient ( IDTYPE,IDNO,NAME,AGE,SEX,ADDRESS,CONTACT_NO,DATE,DOCTOR_CONSULTED,CONSULTATION_REASON,DEPARTMENT,ALLERGIES,INSURANCE,TEMPERATURE,FEES)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """
recordTuple = (idtype,idno,name,age,sex,address,contactno,date,doccons,reason,dept,aller,insu,temp,fees)
mc.execute(query, recordTuple)
mc.execute("CREATE TABLE "+name+" (NAME VARCHAR(100),CONSULTED_DATE DATE,CONSULTATION_REASON VARCHAR(100),CONSULTED_DOCTOR VARCHAR(100),FEES VARCHAR(100))")
qu="""INSERT INTO """+name+""" (NAME ,CONSULTED_DATE ,CONSULTATION_REASON ,CONSULTED_DOCTOR ,FEES )
VALUES(%s, %s, %s, %s, %s)"""
retu=(name,date,reason,doccons,fees)
mc.execute(qu,retu)
db.commit()
print("Record inserted successfully into Patient table")
elif myc.Error==error:
print("Failed to insert into MySQL table {}".format(error))
这是我为学校项目编写的代码。这是库中的一个模块。问题是:当我这样运行模块时,它只会要求插入一条记录,但是当我在另一个程序中调用该模块时,它会要求插入两条记录。但我只想给出一个记录。
任何答案将不胜感激。谢谢。
慕仙森
相关分类