2
People help me there, I’m creating a user manager with level system. however I am not able to pass a value of the variable defined by input() to the INSERT. please help me.
code:
def registrar_usuario():
print("id:")
id_bd = input()
print("level:")
level_bd = input()
print("usuario:")
usuario_bd = input()
print("senha:")
senha_bd = input()
criar_usuarios = " INSERT INTO `usuarios` (`id`, `level`, `usuario`, `senha`) VALUES(%s,%s,%s,%s) (id_bd, level_bd, usuario_bd, senha_bd) "
banco_de_dados.execute(criar_usuarios)
Hello Ghost Designer, what is the error message that returns?
– Éder Garcia
Essa aqui amigo: mysql.connector.errors.Programmingerror: 1064 (42000): You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '%s,%s,%s,%s,%s) (id_bd, level_bd, usuario_bd, senha_bd)' at line 1
– Ghost Designer
Try this way: crea_usuarios = "INSERT INTO usuarios ('id', 'level', 'user', 'password') VALUES(%s,%s,%s,%s) (id_bd, level_bd, usuario_bd, senha_bd)"
– Éder Garcia
Not the same error occurred.
– Ghost Designer
Hello Ghost, I tested the code of my answer here and it worked right. Tip: Create a file called teste_insert.py and paste the code of my answer. To make it work I used the XAMP and Mysql connector. In XAMP you create a bank equal to my answer. In "user" you put root and the password leaves blank. Doing this will work, then just adapt the code to do what you need. Hug!
– Éder Garcia
https://dev.mysql.com/downloads/connector/python/
– Éder Garcia