1

Im trying convert to str


import mysql.connector
from mysql.connector import Error

def VeriEkleme(Deger1,Deger2):
    try:
        connection = mysql.connector.connect(host='localhost',database='pythonregister',user='pyroot',password='')

        if connection.is_connected():
            print("MySQL bağlantısı aktif edildi.")

        mySql_insert_query = """INSERT INTO userinformations (Username, Password) VALUES """(Deger1,Deger2)
        cursor = connection.cursor()
        result = cursor.execute(mySql_insert_query)
        connection.commit()
        print("Record inserted successfully into Laptop table")
        cursor.close()

    except Error as e:
        print("Error while connecting to MysqL", e)

def Register():
    Username = input("Username:")
    Password = input("Pass:")
    VeriEkleme(str(Username),str(Password))


def EnterSystem():
    Login = "login"
    Answer = input("Login or Register?: ").lower()
    if Answer == Login:
        print("eşit")
        Register()
    else:
        EnterSystem()

EnterSystem()

Login or Register?: login
eşit
Username:s
Pass:s
MySQL bağlantısı aktif edildi.
Traceback (most recent call last):
  File "C:/Users/Relov/PycharmProjects/PygameProje1/PygameProjesi.py", line 36, in <module>
    EnterSystem()
  File "C:/Users/Relov/PycharmProjects/PygameProje1/PygameProjesi.py", line 32, in EnterSystem
    Register()
  File "C:/Users/Relov/PycharmProjects/PygameProje1/PygameProjesi.py", line 24, in Register
    VeriEkleme(str(Username),str(Password))
  File "C:/Users/Relov/PycharmProjects/PygameProje1/PygameProjesi.py", line 11, in VeriEkleme
    mySql_insert_query = """INSERT INTO userinformations (Username, Password) VALUES """(Deger1,Deger2)
TypeError: 'str' object is not callable

Process finished with exit code 1
1
  • 2
    This post could use some cleanup. There is a lot of code here without much description, and the error is actually a simple one, but one has to trace a lot of lines to see that you tried to call a string by having parentheses after a string. It's a good first post though. COnsider trying to describe what you are doing in the body a little more. Commented Oct 25, 2019 at 18:03

1 Answer 1

3

You're calling str as it is a function.

"""INSERT INTO userinformations (Username, Password) VALUES """(Deger1,Deger2)

I recommend using Prepared Statements. This is safe against SQL Injection attacks.

mySql_insert_query = """INSERT INTO userinformations (Username, Password) VALUES (%s, %s)"""
cursor = connection.cursor()
result = cursor.execute(mySql_insert_query, (Deger1, Deger2))
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! So what does this %s mean? How does it perceive? Like 1st value 2st value?
@DogukanInce In this context, %s is used to add dynamically changing variables, such as user input, to SQL. Generally used to mean string substitution. 1st value and 2nd value is correct.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.