Posts: 116
Threads: 1
Joined: Apr 2018
You forgot to call the create_table function:
import sqlite3
conn = sqlite3.connect('dfsl.db')
c = conn.cursor()
def create_table():
c.execute("CREATE TABLE orders (Client TEXT, Model TEXT, Quantity INTEGER, Order_date TEXT, Delivery_date TEXT)")
def dynamic_data_entry():
client = input("client: ")
model = input("model: ")
quantity = input("quantity: ")
order_date = input("order date: ")
delivery_date = input("Delivery date: ")
c.execute("INSERT INTO orders (Client, Model, Quantity, Order_date, Delivery_date) VALUES (?, ?, ?, ?, ?)",
(client, model, quantity, order_date, delivery_date))
conn.commit()
# Create the table first
create_table()
# Input the data later
dynamic_data_entry()
conn.close() Also remember that CREATE TABLE will fail if the table exists already in the DB (you can use "CREATE TABLE IF NOT EXISTS")
Posts: 21
Threads: 6
Joined: May 2018
May-17-2018, 10:20 PM
(This post was last modified: May-17-2018, 10:35 PM by D_frucht.)
GREAT thanks !
it created the table, but i still have the problem that when i'm trying to input regullar letters, it comes up with error:
[python]
client: AS
Traceback (most recent call last):
File "/Users/davidfrucht/PycharmProjects/untitled1/DFSL.py", line 24, in <module>
dynamic_data_entry()
File "/Users/davidfrucht/PycharmProjects/untitled1/DFSL.py", line 11, in dynamic_data_entry
client = input("client: ")
File "<string>", line 1, in <module>
NameError: name 'AS' is not defined
[python]
Posts: 536
Threads: 0
Joined: Feb 2018
May-18-2018, 12:18 AM
(This post was last modified: May-18-2018, 12:19 AM by woooee.)
For Python2.X use raw_input() instead of input(). Post the version that you are using when asking a question.
Posts: 21
Threads: 6
Joined: May 2018
Posts: 21
Threads: 6
Joined: May 2018
May-18-2018, 05:24 AM
(This post was last modified: May-18-2018, 05:28 AM by j.crater.)
although Client, Models, etc., defined as TEXT, while entering values in text, the program crash (see below the code). but if i enter numbers, it continue.
im using python 3
import sqlite3
conn = sqlite3.connect('dfsl.db')
c = conn.cursor()
def create_table():
c.execute("CREATE TABLE IF NOT EXISTS orders (Client TEXT, Model TEXT, Quantity TEXT, Order_date TEXT, Delivery_date TEXT)")
conn.commit()
def dynamic_data_entry():
client = input("client: ")
model = input("model: ")
quantity = input("quantity: ")
order_date = input("order date: ")
delivery_date = input("Delivery date: ")
c.execute("INSERT INTO orders (Client, Model, Quantity, Order_date, Delivery_date) VALUES (?, ?, ?, ?, ?)",
(client, model, quantity, order_date, delivery_date))
conn.commit()
create_table()
dynamic_data_entry()
conn.close() error message:
Error: Traceback (most recent call last):
File "/Users/davidfrucht/PycharmProjects/untitled1/DFSL.py", line 27, in <module>
dynamic_data_entry()
File "/Users/davidfrucht/PycharmProjects/untitled1/DFSL.py", line 13, in dynamic_data_entry
client = input("client: ")
File "<string>", line 1, in <module>
NameError: name 'h' is not defined
Posts: 1,150
Threads: 42
Joined: Sep 2016
May-18-2018, 05:38 AM
(This post was last modified: May-18-2018, 05:38 AM by j.crater.)
You need to use [/python] as closing tag, put error message in error tags. You have been warned before.
Are you using Python 2 or 3?
p.s.:
Ah I see the edit now.
You'll probably have to put the text you enter in single quotes. Or you can modifiy the code to place the quotes around the text automatically, if you do not want to do it at input.
Posts: 21
Threads: 6
Joined: May 2018
Im sorry for the /python
Im using python 3
Posts: 1,150
Threads: 42
Joined: Sep 2016
I've edited my previous post, see if my proposed solution works.
Posts: 21
Threads: 6
Joined: May 2018
Unfortunately im not newr the pc, but im quite sure that one of the things i tried is to make it single quote.
Posts: 8,152
Threads: 160
Joined: Sep 2016
May-18-2018, 06:07 AM
(This post was last modified: May-18-2018, 06:07 AM by buran.)
This error shows that you [mistakenly] run the file with python2. You did enter h as input, right?
|