1

Seems like array element index isn't a type that SQLite INSERT will allow.

contact[0] = raw_input("Last Name: ")
contact[1] = raw_input("First Name: ")
contact[2] = raw_input("Street Address: ")
contact[3] = raw_input("City: ")
contact[4] = raw_input("State: ")
contact[5] = raw_input("Zip Code: ")
contact[6] = raw_input("Phone: ")
contact[7] = raw_input("Email: ")

cur.execute("INSERT INTO Contacts VALUES(contact[0], contact[1], contact[2], contact[3], contact[4], contact[5], contact[6], contact[7])")

Is there a way to do this? Thanks!

1 Answer 1

1

How about making it a bit cleaner:

labels = [
    "Last Name: ", 
    "First Name: ", 
    "Street Address: ", 
    "City: ", 
    "State: ",
    "Zip Code: ",
    "Phone: ",
    "Email: "
]
contact = [raw_input(label) for label in labels]
cur.execute("INSERT INTO Contacts VALUES(?, ?, ?, ?, ?, ?, ?, ?)", contact)

where ? are placeholders for query parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.