Python Forum
Need help with code - thanks!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with code - thanks!
#11
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))
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
#12
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
Reply
#13
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
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
#14
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
Reply
#15
(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))
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
#16
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'
Reply
#17
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!
Reply


Forum Jump:

User Panel Messages

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