代码在没有函数的情况下正常运行,但是当我把它放在像这样的函数下面时,它就不能工作,并抛出错误,我在googled上搜索了解决方案,但是它没有工作,所以对于像我这样的初学者来说,您的帮助将是惊人的。
def updatedetails():
getpid = str(search_box.get())
my_cursor.execute("SELECT * from patient_tbll where PID = '"+getpid+"'")
output=my_cursor.fetchone()[1]
print(output)my_cursor.fetchone()[1]上的错误:
TypeError:'NoneType‘对象不能订阅
发布于 2022-03-02 12:30:55
您不应该进行这样的查询,因为它允许在没有适当消毒的情况下进行注射。
我建议您查看您正在使用的MySQL库的文档,因为有些文档可能有所不同。
例如MySQL.connector
select_stmt = "SELECT * FROM employees WHERE emp_no = %(emp_no)s"
cursor.execute(select_stmt, { 'emp_no': 2 })或
sql = "SELECT * FROM customers WHERE address = %s"
adr = ("Yellow Garden 2", )
cursor.execute(sql, adr)fetchone()将返回一个tuple,尝试:
output=my_cursor.fetchone()
print(output[1])打印(输出)以查看实际返回的游标。
https://stackoverflow.com/questions/71322700
复制相似问题