SQLite-Python "executemany()" not executing to the database
<p>I need to get this program to store the values for a persons firstname and surname in a database. The database is called Class and the table inside it that I am trying to insert data into is called Names. 
I have tried to rearrange this several times and removed it from its try loop to try diagnose the issue. Thanks in advance. I will help the best I can :)</p>

<pre><code>new_first,new_surname = str(input("Firstname:\t")), str(input("Surname:\t"))
new_name = [new_surname, new_first]
print(new_name)
c.executemany("INSERT INTO Names VALUES (?,?)", new_name)
</code></pre>

<p>The error message I keep getting is:
Incorrect number of bindings supplied. The current statement uses 2, and there are 7 supplied.</p>

<p>Don't use <code>cursor.executemany()</code>, use <code>cursor.execute()</code>:</p>

<pre><code>c.execute("INSERT INTO Names VALUES (?,?)", new_name)
</code></pre>

<p><code>executemany()</code> should be used for <em>multiple rows of data</em>, but you have just one. </p>

<p>The error is caused by the <code>executemany()</code> method treating <code>new_surname</code> as a row by itself, and since a string is iterable an attempt is made to use every individual character from that string as a parameter. A string length of 7 would give you 7 parameters, and that doesn't match the 2 in the SQL statement.</p>

<p>If you <em>do</em> have many rows, then each row would have to consist of a last and first name value for the two parameters:</p>

<pre><code>new_names = [
    [new_surname, new_first],
    ['another surname', 'another first name'],
    # ...
]
c.executemany("INSERT INTO Names VALUES (?,?)", new_names)
</code></pre>

python sqlite