SQL issue with my code. Database not parsing into app

18 views Asked by At

I'm doing a project for the complete Python course on Stackskills, and I have a problem running an app that should add a book name and author to a database. when I try to add a book, this is what happens:

Your choice: a
What is the name of the book you want to add? clean code
Who is the author of the book? jose
Unknown command, please try again.

it seems like the app.py just forgets it is running prompt_add_book() and starts from the beginning when it asks for a book. I'm not sure what is going wrong here. any help would be appreciated.

def prompt_add_book():
    name = input("What is the name of the book you want to add? ")
    author = input("Who is the author of the book? ")
    database.insert_book(name, author)
def insert_book(name:str, author : str):
    with DatabaseConnection('data.db') as connection:
        cursor = connection.cursor()
        cursor.execute('INSERT INTO books(name,author) VALUES (?, ?)', (name,author))

I was expecting for the book to be added to the database. It was working before, when I wasn't using sqlite3 and just putting the books into a file, but for some reason it is not working when SQL is involved.

0

There are 0 answers