Python Forum
Concatenating strings in cgi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concatenating strings in cgi
#1
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
Reply
#2
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
Recommended Tutorials:
Reply
#3
Oh thank you, metulburr, for that. Yeah, the error was removed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 699 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,704 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  concatenating 2 items at a time in a python list K11 3 2,246 Oct-21-2020, 09:34 AM
Last Post: buran
  concatenating lists in a comprehension Skaperen 3 2,089 Jan-01-2020, 08:10 PM
Last Post: ichabod801
  Finding multiple strings between the two same strings Slither 1 2,482 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  concatenating list with tuple Skaperen 7 4,328 Sep-28-2018, 05:55 AM
Last Post: Skaperen
  lists, strings, and byte strings Skaperen 2 4,183 Mar-02-2018, 02:12 AM
Last Post: Skaperen
  How to create a long string by concatenating two lists nikhilkumar 11 7,444 Jul-12-2017, 05:36 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020