so I'm trying to test my code and have made quite a few changes but each time I am getting '500 internal server error'. I don't get what I'm doing wrong. I also don't know where I can look for a better description of the error.
Thanks.
Edit: added code at the bottom.
This is my code:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
new = open("survey.ssv", "r+")
new.write(form.getvalue("surveyQuestion")+"\n")
new.seek(0)
lines = new.readlines()
i = 0
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Create-a-Survey!</title>"
print "</head>"
print "<body bgcolor='white' text='black'>"
print "<center>"
print "<h1>Create Survey Page</h>"
print "</center>"
print "To create a survey first input a title in the 'Survey Title' text box. To add questions, write a question in the 'Survey Question' text box and click the 'Add' button. If you want to create a new survey, write a new survey title and click 'New'. The 'Done' button will end the survey creation and return you to the welcome page."
print "<br><br>"
for line in lines:
if i == 0:
print "Current Survey Title:<br>%s" % line
print "<br><br>"
print '<form action="newSurvey.py" method="post">'
print 'Survey Title:<br><input type="text" name="surveyTitle">'
print '<input type="submit" name="decision" value="New">'
print '</form>'
print '<br><br>'
else:
print "Question %d:<br>%s" % i, % line
print '<br><br>'
i = i + 1
new.close()
print '<form action="addQuestion.py" method="post">'
print 'Survey Question:<br><input type="text" name="surveyQuestion">'
print '<br><br>'
print '<input type="submit" name="decision" value="Add">'
print '</form>'
print '<form action="doneSurvey.py" method="post">'
print '<input type="submit" name="decision" value="Done">'
print '</form>'
print '<a href="welcome.html">Back to welcome page</a>'
print '</body>'
print '</html>'
This is code that's currently working, and is the one that I end up running before the code above:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable() # enable debugging mode
form = cgi.FieldStorage()
new = open("survey.ssv", "r+")
new.write(form.getvalue("surveyQuestion")+"\n")
lines = new.readlines()
i = 0
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Create-a-Survey!</title>"
print "</head>"
print "<body bgcolor='white' text='black'>"
print "<center>"
print "<h1>Create Survey Page</h>"
print "</center>"
print "To create a survey first input a title in the 'Survey Title' text box. To add questions, write a question in the 'Survey Question' text box and click the 'Add' button. If you want to create a new survey, write a new survey title and click 'New'. The 'Done' button will end the survey creation and return you to the welcome page."
print "<br><br>"
for line in lines:
if i == 0:
print "Current Survey Title:<br>%s" % line
print "<br><br>"
print '<form action="newSurvey.py" method="post">'
print 'Survey Title:<br><input type="text" name="surveyTitle">'
print '<input type="submit" name="decision" value="New">'
print '</form>'
print '<br><br>'
else:
print "Question %d:<br>%s" % i, % line
print '<br><br>'
i = i + 1
new.close()
print '<form action="addQuestion.py" method="post">'
print 'Survey Question:<br><input type="text" name="surveyQuestion">'
print '<br><br>'
print '<input type="submit" name="decision" value="Add">'
print '</form>'
print '<form action="doneSurvey.py" method="post">'
print '<input type="submit" name="decision" value="Done">'
print '</form>'
print '<a href="welcome.html">Back to welcome page</a>'
print '</body>'
print '</html>'
This line is not valid Python:
print "Question %d:<br>%s" % i, % line
If you want to interpolate two values, use a tuple:
print "Question %d:<br>%s" % (i, line)