0

I have created a variable named hash as a password hash. How can this variable be inserted a a field value in a table?

hash = pbkdf2_sha256.encrypt("password", rounds=200000, salt_size=16)
cur.execute("insert into meanu(username,pwdhash1) values('BV2',hash)")
produces following error:
mysql_exceptions.OperationalError: (1054, "Unknown column 'hash' in 'field list'")
mysql_exceptions.OperationalError: (1054, "Unknown column 'hash' in 'field list'")

cur.execute("insert into meanu(username,pwdhash1) values('BV2','hash')") inserts the literal "hash" as the field value.

3
  • I think you need quotes around hash
    – Mihai
    May 16 '15 at 6:46
  • Mihal, that doesn't insert the variable hash, but the entry is the literal word hash. May 16 '15 at 7:59
  • 1
    In which context are you using hash = ... and cur.execute(...) ?
    – Eric Ly
    May 16 '15 at 8:03
0

You should insert hash as a parameter following this example: http://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html

Something like this

insert_stmt=(
       "insert into meanu (username,pwdhash1)"
       " values('BV2',%s)"
        )
data=(hash)
cursor.execute(insert_stmt, data)
1
  • Thank you very much! It works perfectly. Have a great weekend, Robert May 16 '15 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.