[Tutor] help

james middendorff james2dope at yahoo.com
Wed Feb 9 05:35:39 CET 2005


I want to use mysqldb to add people into a database,
but when I ask for the certain fields like Name,
PhoneNumber and such, I cannot get it to put them in
as a string? I am not sure what I am doing wrong but
here is my code thanks to anyone who helps:
import MySQLdb

username = raw_input("what is your username? ")
password = raw_input("what is the password? ")
database = raw_input("what database do you want to
enter? ")
conn = MySQLdb.connect(host='127.0.0.1',
user=username, passwd=password, db=database)

c = conn.cursor()

Name = raw_input("what is the name you want to add? ")
PhoneNumber = input("what is the phone number for the
person you are adding? ")
Address = raw_input("what is the address for the
person you are adding? ")
EmailAddress = raw_input("what is the email address of
the person you are adding? ")
BirthDate = raw_input("what is the birthdate of the
person you are adding? year-month-day")


c.execute ("""
            INSERT INTO people ()
            VALUES
               ('%s','%s','%s','%s','%s');
           """)% (Name, PhoneNumber, Address,
EmailAddress, BirthDate)
           
print "%d rows were inserted" % c.rowcount

=====
"I would kill everyone in this room
    for a drop of sweet beer."
     ----Homer Simpson----


		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 


More information about the Tutor mailing list