2013-04-09 85 views
3
team = input("Enter the team name: ") 

cursor = db.cursor() 

sql = "SELECT * FROM `flash_data_archive` WHERE `event_id` IN (SELECT `alternate_id` from `event_list` where `category` = %s)" % team 

cursor.execute(sql) 

什么是正确的符号有用户对“团队”中输入的字符串用于在SQL subsuery类别字段使用Python变量?在MySQL子查询

回答

3

从字符串中删除% team。相反,它应该是.execute的参数。

cursor.execute(sql, team) 

这将正确地逃避它。

+0

修复它,非常感谢! – alpswd 2013-04-09 04:29:53

+1

@alpswd不要忘记注册并接受有帮助的答案 – 2013-04-09 04:30:33