Aug-28-2019, 05:23 AM
I am using Python 3.4. I was working on cgi programming. I created checkboxes and wanted to get those input values as string and post it in single field in MySQL database. When I add strings in IDLE as normal program I get output, but in cgi same code produces error as bad headers.
HTML code:
Select hobbies</td><td>Books<input type="checkbox" name="books" value="books">Crafts<input type="checkbox" name="crafts" value="crafts">Tailoring/Embroidery<input type="checkbox" name="tailor" value="tailoring">
<python>
import cgi
form1 = cgi.FieldStorage()
books = str(form1.getvalue('books'))
crafts = str(form1.getvalue('crafts'))
tailor = str(form1.getvalue('tailor'))
hobbies = books + crafts + tailor
print (hobbies)
</python>
hobbies variable gets printed, whereas the browser throws error as bad header for the above code where concatenate three strings
HTML code:
Select hobbies</td><td>Books<input type="checkbox" name="books" value="books">Crafts<input type="checkbox" name="crafts" value="crafts">Tailoring/Embroidery<input type="checkbox" name="tailor" value="tailoring">
<python>
import cgi
form1 = cgi.FieldStorage()
books = str(form1.getvalue('books'))
crafts = str(form1.getvalue('crafts'))
tailor = str(form1.getvalue('tailor'))
hobbies = books + crafts + tailor
print (hobbies)
</python>
hobbies variable gets printed, whereas the browser throws error as bad header for the above code where concatenate three strings