database - Why it gives me Type error in that code? -


why gives me (type error) in statment " address = cur.fetchone()[2] last = cur.fetchone()[4] no = cur.fetchone()[5] , while accept "name = cur.fetchone()[1]" in code : "

import sqlite3 conn = sqlite3.connect('myproject.sqlite') cur = conn.cursor() print "welcome mr/hefnawy" cur.execute('select phone participants') b = cur.fetchone()[0] while true:     = raw_input("enter phone number here : ")     if == b :         cur.execute('select name,address,last_order,no_of_orders    participants phone = ?',(b, ))         name = cur.fetchone()[1]         address = cur.fetchone()[2]         last = cur.fetchone()[4]         no = cur.fetchone()[5]         print "the costumer exist in paricipants "         print "to edit costumer data press (1)", "\n" , "to delet    costumer press (2)", "\n" , "add new order costumer press (3) "         c = raw_input("enter choice here : ")         if c == "1":             print "what want edit ? , edit name press 1 , edit address press 2 , edit phone press 3"             d = raw_input("enter choice here : ")             if d == "1" :                 e = raw_input("new costumer name please ")                 cur.execute('update participants set name = ? phone = ?' , (e , a))                 print "costumer name has been updated :", e                 print ""                 conn.commit()     else:         print "the costumer not exist"         print b         print , type(a) 

when fetching cursor example

t = cur.fetchone() 

you can access data t using print t[0],t[1],t[2] in case using multiple cur.fetchone() allows use name = cur.fetchone()[1] ends data in cursor. second line address = cur.fetchone()[2] , lines follow not have sql query executed them fetch, hence giving error. if want access whole row assign variable , use variable data.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -