niedziela, 1 września 2013

isert data to db from raw_input

#!/usr/bin/python


import MySQLdb as mdb
name = str(raw_input('enter name: '))
surname = str(raw_input('enter surname: '))
con = mdb.connect('localhost', 'root', 'password', 'baza');

with con:

        cur = con.cursor()
        cur.execute("INSERT INTO adresy(imie,nazwisko) VALUES('"+name+"', '"+surname+"')")

        cur.execute("Select * from baza.adresy")
        for row in cur.fetchall():
                id = str(row[0])
                imie = str(row[1])
                nazwisko = str(row[2])

                print "id: ",id
                print "imie: ",imie
                print "nazwisko: ",nazwisko
                print "--------"
        cur.close()

Brak komentarzy:

Prześlij komentarz