Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database input by user
#1
Hello,
I am a python beginner, covered all the basics. To really learn pythoon i though that it will be a good idea to just dive in and start working on some projects of my own. The first one is suppose to be simple...although i didnt find and tutorial:

I want to build a program for my company that organize all the orders we get from our clients: Model name, Quantity, Client, Date of order, Date of our Derlivery obloighation

All of the above should be entered by our workers. Then i will output a table with all orders.

I tried to do it with mysql, but i didnt fins any tutorial explaining how a user of the program will enter thr pramaters. Im quite sure that it is related to “input” function, but i didnt had any luck with it...If there is a tutorial that explains that i will be more than happy to read it, because im also a fan of RTFM approch.

Thanks
Reply
#2
https://www.elated.com/articles/mysql-fo...beginners/
Reply
#3
@larz60 thanks for your prompt answer, but i still stuck in the same problem - how a user can enter the data in the table, and not the programmer
Reply
#4
I don't use MySQL, but all databases have an interactive query program.
In MySQL, it's simply called mysql
from a command line, type mysql
then you can enter SQL queries for creating tables, inserting data and whatever else you need, See: https://dev.mysql.com/doc/refman/8.0/en/...eries.html
If you don't know SQL, you need to take an SQL tutorial.
Reply
#5
@Larz60+, I'm pretty sure OP wants to interact with MySQL using python :-)
@D_frucht: So basically you need a package to work with MySQL from python.
some resources:
https://dev.mysql.com/doc/connector-pyth...ction.html

or using SQLalchemy
https://www.sqlalchemy.org/


https://www.tutorialspoint.com/python/py...access.htm
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
Dear friends !

I see now a mistake in my question - iment sqlite not mysql
Reply
#7
Well, more or less same advice:
https://docs.python.org/3/library/sqlite3.html
It's part of the standard library, so no need to install anything. Yet you still msy use SQLalchemy if you decide so
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
first:
import sqlite3
Then the remainder depends on exactly what you want to do.
Follow examples here: https://docs.python.org/2/library/sqlite3.html
Reply
#9
this is my code, can someone explain what im doing wrong?

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 INTEGER, order_date TEXT, delivery_date TEXT )')

def data_entry():
    c.execute("INSERT INTO orders VALUES('client', 'model', 'quantity', 'order_date', 'delivery_date')")

    conn.commit()
    c.close()
    conn.close()



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()

for i in range(10):
    dynamic_data_entry()

c.close()
conn.close()
Reply
#10
i have 2 problems with the code below:

although Client, Models, etc., defined as TEXT, while entering values in text, the program crash. but if i enter numbers, it continue.

the other problem is, after entering the data (using the input), i get this error message:

Output:
client: 56 model: 45 quantity: 345 order date: 345 Delivery date: 45 Traceback (most recent call last): File "/Users/davidfrucht/PycharmProjects/untitled1/DFSL.py", line 22, in <module> dynamic_data_entry() File "/Users/davidfrucht/PycharmProjects/untitled1/DFSL.py", line 18, in dynamic_data_entry (client, model, quantity, order_date, delivery_date)) sqlite3.OperationalError: no such table: orders Process finished with exit code 1
here is the code

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()

dynamic_data_entry()

conn.close()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,141 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 988 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,132 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,171 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,168 Dec-11-2022, 07:39 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 2,040 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 1,248 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 1,978 May-10-2022, 02:44 AM
Last Post: alisha17
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,547 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Matplotlib - close multple plots with user input Positron79 0 1,804 Dec-01-2021, 05:26 PM
Last Post: Positron79

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020