Hi,
I have been looking at a few tasks I want to do using a MySQL DB and Python. Therefor I'm spending some time looking at the MySQLdb module for Python and how I can use it.
I've worked out a few bits but I want to be able to use user input to enter data instead of having to edit the python script values each time
I found a few alternatives on here and have a single very simple version working:
import MySQLdb
db = MySQLdb.connect("localhost","root","reverend","TESTDB" )
cursor = db.cursor()
staff_first = raw_input("What is your first name? ")
#staff_last = raw_input("What is your second name? ")
sql="""INSERT INTO STAFF(FIRST_NAME) VALUES('%s')""" % staff_first
cursor.execute(sql)
db.commit()
db.close()
This is working so far as it is getting the first name in - but I can't seem to be able to edit the script to allow each input to work (I have commented out staff_last for now - but I would like that information to be requested at some point).
Can someone give me an example of how I can do this - altering the script to allow more that 1 input per line (even if it's just a hint to get me thinking)?
I tried a few different versions altering the values and the field names etc but I keep getting errors when run.
I'm still a bit of a beginner when it comes to programming - and so it's taking a while to sift through and understand some of the errors I am getting.
Thanks!