python 3.x - How do i use input variables to locate ids with UPDATE in sqlite3? -


i'm trying make contacts list manageable user input. program asks user wants do, either add new contact, edit contact, delete contact or show list of contacts, if user wants edit contacts he's asked id of contact wants change, , row wants change(name, lastname or number).. don't know is, how go using sql update command id user gave, , how use new name, or last name or number given user same command, update? user can pick contact edit , parameter edit menu.

here's code.

import sqlite3  asd = true while asd:     conn = sqlite3.connect('contactsdb.db')     c = conn.cursor()     c.execute('''drop table if exists contacts''')     c.execute('''create table contacts                   (id integer primary key, nombre text, apellido text, numero de celular integer)''')      # def agregarconbg():     #     global nombre     #     global apellido     #     global numero      def agregarcon():         nombre = input("add name")         apellido = input("add lastname")         numero = input("add number")         # c = conn.cursor()         c.execute("insert contacts (nombre, apellido, numero) values(?,?,?);",(nombre,apellido,numero))         conn.commit()      def editnom():         nuevonom = input("add new name")         ###################################################         ###################################################         #########what do around here?!################         c.execute("update contacts set nombre id=1",(nuevonom))         conn.commit     # def editap():     #     # def editnum():      def editarcon():         print ("what id want change?")         cambiar = input("introduce id want change:")         print("""what want change         1 - name         2 - lastname         3 - number""")         cambiarpar = int(input("seleccion:"))         if cambiarpar == 1:             editnom()         elif cambiarpar == 2:             editap()         elif cambiarpar == 3:             editnum()         else:             print("wrong input")         # c = conn.cursor()       #def borrarcon():     #    c = conn.cursor()     def printsql():         # c = conn.cursor()         c.execute('select * contacts order id')         listt = ["id","nombre:","apellido:","numero:"]         k = 0         in c:             print("\n")             j in i:                 print (listt[k])                 print(j)                 if k < 3: k+=1                 else: k = 0     conn.commit()      print('agenda de contactos')     print('''que deseas hacer?     1 - add contact     2 - edit contact     3 - delete contact     4 - show contacts''')      seleccion = int(input("seleccion:"))      if seleccion == 1:         agregarcon()     elif seleccion == 2:         editarcon()         conn.commit()     elif seleccion == 3:         borrarcon()         conn.commit     elif seleccion == 4:         printsql() 

pass cambiar(id) through parameter editnom() , use part of update statement, plus use nombre = variable update record

see page sqlite3 update

see how pass variables through functions in python

def editnom(cambiar): nuevonom = input("add new name") ################################################### ################################################### #########what do around here?!################ c.execute("update contacts set nombre = ? id=?",(nuevonom,cambiar)) conn.commit

if cambiarpar == 1: editnom(cambiar)


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -