Python Forum

Full Version: Concatenating strings in cgi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
When you print in CGI the first character must be the header
Content-type: text/html\n
Followed by an empty line
Then your content
https://python-forum.io/Thread-Run-Pytho...rom-Apache
Oh thank you, metulburr, for that. Yeah, the error was removed.