Ask coding questions

← Back to all posts
Python Database
AarjavKavathia (0)

Hi.

I am trying to program an sql database in python that asks for your name and stores it in a database. The problem is that it stores it but then when I reload, the data is gone. Here is the code:

import sqlite3

conn = sqlite3.connect('python.db')
c = conn.cursor()

def create_table():
c.execute('CREATE TABLE IF NOT EXISTS RecordONE (Number REAL, Name TEXT)')
name = input("What is your name?")
def data_entry():
number = "1234"
c.execute("INSERT INTO RecordONE (Number, Name) VALUES(?, ?)", (number, name))
conn.commit()

create_table()
data_entry()

c.close()
conn.close()

What could the problem be?

Thank you

Comments
hotnewtop
GABELACANLALE (33)

you forgot to put "c.read()" which makes sure to save and read the program.