 <p>You must use string formatting to substitute variable for its value</p> <pre><code>cursor.execute("UPDATE `ISEF_DB`.`attendance` SET `present`='1' WHERE `id` = '%s'" % data) </code></pre> <p>Although be warned that this leaves you susceptible to <a href="https://www.owasp.org/index.php/SQL_Injection" rel="nofollow">SQL Injection</a>. To prevent that you can use exceute like so (<a href="http://mysql-python.sourceforge.net/MySQLdb.html#some-examples" rel="nofollow">from the docs</a>)</p> <pre><code>cursor.execute("UPDATE `ISEF_DB`.`attendance` SET `present`='1' WHERE `id` = '%s'", (data,)) </code></pre> <p>i.e. pass the values as tuples to <code>execute</code>. More information about avoiding SQL injection when using MySQLDB can be found in <a href="http://stackoverflow.com/questions/7929364/python-best-practice-and-securest-to-connect-to-mysql-and-execute-queries">this question</a></p>