where my code is
import mysql.connector
def tablec():
db = input("Enter the Database to create a Table : ")
table = input("Enter the table name : ")
c1name = input("Enter the 1st column name : ")
c1type = input("Enter the 1st column Datatype : ")
c1size = input("Enter the 1st column's size : ")
c2name = input("Enter the 2nd column name : ")
c2type = input("Enter the 2nd column Datatype : ")
c2size = input("Enter the 2nd column's size : ")
cn = mysql.connector.connect(host='localhost', user='root', passwd='0221', database=db)
cur = cn.cursor()
cur.execute("createtable {0}.{1} ({2} {3} {4}, {5} {6} {7})".format(db, table, c1name, c1type, c1size, c2name, c2type, c2size))
cur.execute("select * from {0}.{1}".format(db, table))
def Insert():
dba = input("Enter the Database : ")
tbl = input("Enter the Table : ")
ic1 = input("Enter the insert 1st name or number : ")
ic2 = input("Enter the insert 2nd name or number : ")
con = mysql.connector.connect(host='localhost', user='root', passwd='0221', database=dba)
cr = con.cursor()
cr.execute("insert into {dba}.{tbl} values {ic1},{ic2}")
cr.execute("select * from {dba}.{table}")
def Remove():
dbs = input("Enter the Database : ")
tabl = input("Enter the Table : ")
dc1 = input("Enter the Unique name or number to delete : ")
coon = mysql.connector.connect(host='localhost', user='root', passwd='0221', database=dbs)
cr = coon.cursor()
cr.execute("delete from {dbs}.{tbl} where {dc1}")
cr.execute("select * from {dbs}.{table}")
def Update():
dbt = input("Enter the Database : ")
tab = input("Enter the Table : ")
wc1 = input("Enter the Unique name or number to update : ")
uc2 = input("Enter the replace name or number : ")
co = mysql.connector.connect(host='localhost', user='root', passwd='0221', database=dbs)
cr = co.cursor()
cr.execute("update {0}.{1} set {2} where {3}")
cr.execute("select * from {dbt}.{table}")
ch = input("Do You To Continue (y for yes or n for no) : ")
while ch!="n":
choice = input("Enter the choice :\n1)Create Table\t2)Insert\t3)Remove\t4)Update\t5)Exit\n")
if choice==1:
tablec()
elif choice==2:
Insert()
elif choice==3:
Remove()
elif choice==4:
Update()
elif choice==5:
break
What I have tried:
output is :
Do You To Continue (y for yes or n for no) : y
Enter the choice :
1)Create Table 2)Insert 3)Remove 4)Update 5)Exit
5
Enter the choice :
1)Create Table 2)Insert 3)Remove 4)Update 5)Exit