title: How to use variables in Python SQL query?
body: <p>I'm using some copy-pasted code to do SQL queries on a MySQL DB through Python/Flask. I'm not familiar with it and it's telling me the way I'm trying to input a variable is not the correct syntax.</p>
  
  <p>My code runs a query to see if an email already exists.</p>
  
  <p>The problem code:</p>
  
  <pre><code>def check_if_exists(val):
      import mysql.connector
      cnx = mysql.connector.connect(host=0.0.0.0", port=3306, user="username", passwd="password", db="testDB")
      cursor = cnx.cursor()
      query = """SELECT * FROM users WHERE email = val"""
      result = cursor.execute(query)
      print(result)
  </code></pre>
  
  <p>It's assuming <code>val</code> is a column, but I want it to use the function argument instead.</p>
  
  <pre><code>result = check_if_exists('random@email.com')
  &gt;&gt;&gt; True
  </code></pre>