title: UPDATE together with the WHERE statement with variables in sqlite and python
body: <p>I am coding with python and using SQLite. I need to update a table using the UPDATE and WHERE statements. The challenge is that both values for the WHERE and UPDATE statements must be variables. I have done some research and found this link <a href="https://stackoverflow.com/questions/29335050/sqlite3-updating-row-defined-by-a-variable">Sqlite3 Updating Row Defined by a Variable</a> and this <a href="https://www.tutorialspoint.com/sqlite/sqlite_update_query.htm" rel="nofollow noreferrer">https://www.tutorialspoint.com/sqlite/sqlite_update_query.htm</a></p>
  
  <pre><code>def studentlist():
      '''Checks if a student is checked in any class, inserts the status into the
      student list table Displays a list of all students and their class status'''
      c.execute("SELECT StudentID FROM StudentTable")
      all_students = c.fetchall()
      c.execute("SELECT StudentID FROM CheckedInTable")
      selected_student_id = c.fetchall()
      print("The student id in the studentlist is:", selected_student_id,)
      for i in all_students:
          if i in selected_student_id:
              student_attendance = 'Attending a class'
              c.execute("UPDATE StudentlistTable set ClassAttend = ?", (student_attendance), "WHERE StudentID = ?", (i))
              conn.commit()
          else:
              student_attendance = "Not in class"
              c.execute("UPDATE StudentlistTable set ClassAttend = ?", (student_attendance))
              conn.commit()
  studentlist()
  </code></pre>
  
  <p>Upon running the code, I receive the following error</p>
  
  <pre><code>c.execute("UPDATE StudentlistTable set ClassAttend = ?", (student_attendance), "WHERE StudentID = ?", (i))
  TypeError: function takes at most 2 arguments (4 given)
  </code></pre>
  
  <p>Any help would be highly appreciated. </p>