No Output from checkboxes in Python
<p>I'm a newbie to Python and this forum. So I'll try to explain my issue the best I can.<br>
I'm trying to get the results of check boxes to appear along with their corresponding data from fields in an SQLite database. I get in my code if I simply have "print selectedbooks" I get the checkbox results but in order to get the corresponding data from the other fields fields I have the following code. I'm not sure what I'm doing wrong. My code is below. Everything inside the "for" loop will not print</p>

<pre><code>import sys, cgi, cgitb, sqlite3

# Create instance of FieldStorage
form = cgi.FieldStorage()
conn = sqlite3.connect('battleofthebooks.db')
c = conn.cursor()

value = form.getlist('selectedbook')
selectedbook = "&lt;br/&gt;&lt;br /&gt;".join(sorted(value))

print "Content-Type: text/html\r\n\r\n"
print "&lt;html&gt;"
print "&lt;head&gt;"
print "&lt;title&gt;Battle of the Books&lt;/title&gt;"
print "&lt;/head&gt;"
print "&lt;body&gt;"
print "&lt;h3&gt;You have chosen the following books:&lt;/h3&gt;"

print selectedbook
TITLE = ""
for row in c.execute("SELECT * FROM BOBBOOKLIST where TITLE=(?)", (TITLE, )):
    print selectedbook
    print row[2]
    print "&lt;br /&gt;"
    print row[3]
    print "&lt;br /&gt;"
    print "Books in Stock:  ",  row[4]
    print "&lt;br /&gt;"
</code></pre>

<p>Ahh the faithful c.execute operation. Ok. Give the print of </p>

<pre><code>print c.execute("SELECT * FROM BOBBOOKLIST where TITLE=(?)", (TITLE, ))
</code></pre>

<p>then you would be knowing the answer. When c.execute is triggered, the data is new and the cursor is no longer valid to the old one.
You could always store the value of c.execute to a variable, then iterate the variable in the for loop.</p>

python forms variables for-loop cgi