title: How do I pass a variable in an SQL query in python
body: <pre><code>nameEnt = nameEntered.get()
  
  print(nameEnt)
  
  sql = &quot;SELECT * FROM attendance WHERE name=&quot;%s&quot;
  val = (nameEnt)
  print(mycursor.execute(sql, val))
  myresult = mycursor.fetchall()
  for x in myresult:
      print(x)
  </code></pre>
  <p>I would like to pass the string in 'nameEnt' into the SQL query using python. I'm currently using the mysql-connector package. The program keeps telling me that my syntax is incorrect. I can execute the query in SQL directly without any problem.</p>
  <p>I have also tried</p>
  <pre><code>sql = &quot;SELECT * FROM attendance WHERE name= &quot;+nameENt
  </code></pre>