Python Forum

Full Version: Need help with code - thanks!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
1. you miss closing bracket
2. you never pass your values to execute
try
db.execute("INSERT INTO users (username, password) VALUES (:username, :password)" % (username, password))
Hey thanks it's almost there but i'm getting this error now :

TypeError: not all arguments converted during string formatting

I'm looking it up as well
or
db.execute("INSERT INTO users (username, password) VALUES (:username, :password)" username=username, password=password)
I don't use sqlalchemy, so it's a bit trial and error for me too
File "C:\school\project1\application.py", line 61
db.execute("INSERT INTO users (username, password) VALUES (:username, :password)" username=username, password=password)
^
SyntaxError: invalid syntax

I tried a few options I just can't find the correct syntax. So close! Thanks
(Jun-06-2020, 09:22 PM)card51shor Wrote: [ -> ]SyntaxError: invalid syntax
There is missing comma (also in my example)
db.execute("INSERT INTO users (username, password) VALUES (:username, :password)", username=username, password=password)
you may try also
db.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, password))
Thanks so much I'm so frustrated trying to figure this out. I tried both your methods and I'm still getting errors. With the first example u gave me, I get this error:

TypeError: get_bind() got an unexpected keyword argument 'username'


And with the other I get this error:

AttributeError: 'tuple' object has no attribute 'keys'
I fixed the issue with this code:
db.execute("INSERT INTO users (username, password) VALUES (:username, :password)", {"username":username, "password":password})

But now it's entering NULL fields into the database and not what I type into the fields on register.html. Any idea why? Thanks!
Pages: 1 2