2016-08-03 84 views
0
@bot.message_handler(commands=['start']) 
def start(m): 
    cid = m.chat.id 
    secret = id_generator() 
    hashedpw = hashlib.md5(secret).hexdigest() 
    cur.execute("INSERT into `users` (username, password) VALUES (str(cid), str(hashedpw)") 
    bot.send_message(m.chat.id, "Your secret token is " + secret) 

有人可以幫我解決這個問題嗎? 說實話,我不知道這個問題會是什麼。您在SQL語法中有錯誤;檢查對應於您的MariaDB服務器版本的手冊,在第1行的''附近使用正確的語法

+0

哪個教程您使用的? –

回答

0

你在你的SQL語法錯誤

你缺少一個右括號)VALUES

cur.execute("INSERT into `users` (username, password) VALUES (str(cid), str(hashedpw))") 
0

這是因爲你需要傳遞的實際參數到數據庫,這將被引用的字符串 - 例如

cur.execute("INSERT into `users` (username, password) VALUES ('jon','passwd')") 

嘗試類似,它會在你使用的變量的值:

cur.execute("INSERT into `users` (username, password) VALUES (?,?)", (str(cid), str(hashedpw))) 

這個答案可以幫助:

How to use variables in SQL statement in Python?

相關問題