1

I'm building a program, where the user input an enterprise's name to get the code running.

I would like the user to pick the enterprise name in a drop down list, but currently i dont have a GUI to make it work.

so for now, I would like to connect the input function to the SQL database enterprises name column.

I already connected SQL to my python code... but how do I connect MySQL to an input function? I want the user to be able to get the information from the database

MY SQL CONNECTION :

import mysql.connector

mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM listedatabase.entreprises_inspecteurs")

for row in mycursor.fetchall():
    print (row[1])

mydb.close()

python:

enterprise_name = input()

Thank you for helping

I tried this but no luck:

 mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

    mycursor = mydb.cursor()

    enterprise_name = input()
    mycursor.execute("SELECT n_fabricant FROM listedatabase.entreprises_inspecteurs", (enterprise_name,))
    data = mycursor.fetchall()
    if data:
        code goes there
    else: 
        print('data not found in database')
7
  • So where does the enterprise_name go? Commented Apr 27, 2020 at 19:02
  • Like SELECT ... WHERE name=?? Commented Apr 27, 2020 at 19:40
  • @SwetankPoddar it linked to google calendar api. Enterprise_name is represented by the SUMMARY description of an event. Commented Apr 27, 2020 at 22:03
  • @tadman Yes, does it work like that inside a python code? Commented Apr 27, 2020 at 22:04
  • 1
    You need to add a WHERE clause, you can't just attach data. Commented Apr 28, 2020 at 20:23

1 Answer 1

1
 mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

    mycursor = mydb.cursor()

    enterprise_name = input()
    mycursor.execute("""SELECT n_fabricant FROM listedatabase.entreprises_inspecteurs WHERE n_fabricant = %s"""(event_inspecteur,))
    data = mycursor.fetchall()
    if data:
        code goes there
    else: 
        print('data not found in database')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.