Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未知列';名称';在';其中第'条;_Python_Mysql_Sql_Database_Face Recognition - Fatal编程技术网

Python 未知列';名称';在';其中第'条;

Python 未知列';名称';在';其中第'条;,python,mysql,sql,database,face-recognition,Python,Mysql,Sql,Database,Face Recognition,我实际上在一个基于面部识别的考勤系统中工作。 但不幸的是,我在Mysql上遇到了记录出勤率的问题 if True in matches: first_match_index = matches.index(True) name = known_face_names[first_match_index] sql = "UPDATE stud_att SET P1=1 WHERE name = fname" mycursor.execute(sql)

我实际上在一个基于面部识别的考勤系统中工作。 但不幸的是,我在Mysql上遇到了记录出勤率的问题

 if True in matches:
    first_match_index = matches.index(True)
    name = known_face_names[first_match_index]  

    sql = "UPDATE stud_att SET P1=1 WHERE name = fname"
    mycursor.execute(sql)
    mydb.commit()



  draw.rectangle(((left, top), (right, bottom)), outline=(255,255,0))


      text_width, text_height = draw.textsize(name)
      draw.rectangle(((left,bottom - text_height - 10), (right, bottom)), fill=(255,255,0), outline=(255,255,0))
      draw.text((left + 6, bottom - text_height - 5), name, fill=(0,0,0))



    del draw
这是我的代码问题是“where子句”中的
未知列“name”
我不知道哪里错了,我肯定数据库中存在识别系统的名称

我的桌子

fname, lname, ID, P1, P2, P3, P4
Name1,  Name2, 1,

您的列名必须位于
=
的左侧,然后将其与要检查的值进行比较。

您当前的问题是引号问题:在SQL中,字符串需要用单引号括起来;假设
name
是一个字符串,则需要:

mycursor.execute("UPDATE stud_att SET P1 = 1 WHERE fname = '" + name + "'")
但这很容易出错,并且仍然会将代码留给SQL注入。所以:您应该只使用参数化查询:

mycursor.execute("UPDATE stud_att SET P1 = 1 WHERE fname = %s", (name))

给我们看一下你的表stud_att通常mysql并不是这样的如果我理解正确,fname是你的列名之一,而不是名称,对吗?@streof Yes fname是列名,然后您必须交换它们的位置,并确保将
name
作为变量而不是文本字符串串联在“where子句”中的未知列“Name1”
mycursor.execute("UPDATE stud_att SET P1 = 1 WHERE fname = %s", (name))