0

I'm using Python to create a registration system that adds values into an SQLite database. With my code I don't get any errors when ran but the data isn't added into the table.

import sqlite3 as db #Import the SQLite module as db
import smtplib as mail #Importing the send email library as mail
from email.mime.text import MIMEText #Importing the text component of the mail library


#Getting the user to input the their data
username = raw_input("What would you like your username to be? ")
email = raw_input("What is your email address? ")
firstName = raw_input("What is your first name? ")
surname = raw_input("What is your surname? ")
age = raw_input("How old are you? ")
password = raw_input("What is your password?") #Encryption method will be added later
int(age) #Changing the age variable into an integer so it can be inputted into the database

#DB part
conn = db.connect('apollo.db') #Connecting to the database
cursor = conn.cursor()
cursor.execute("INSERT INTO users VALUES(?, ?, ?, ?, ?, ?)",
            (username, email, firstName, surname, age, password)) #Inserting the user's data into the table

conn.close() #Closing the connection

3 Answers 3

3

You need to commit() the changes.

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

Comments

0

Like pbacterio already answered, you have to commit your changes by calling cursor.commit(), so any actions that were buffered (in another file, if i remember correctly) will be written in your database file.

Comments

0

Also use

age= int(age)

int(age) returns integer value but you need to store back.

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.