I’m learning python,, so I got this exercise from a book:
This is an html form:
<html>
<body>
<form method=POST action="cgi-bin/cgi101.py">
<P><b>Enter your name:</b>
<P><input type="text name=user" />
<P><input type="submit" />
</form>
</body>
</html>
And this is the script to call:
#!/usr/bin/python3
import cgi
form = cgi.FieldStorage()
# parse form data
print('Content-type: text/html\n')
# hdr plus blank line
print('<title>Reply Page</title>')
# html reply page
if not 'user' in form:
print('<h1>Who are you?</h1>')
else:
print('<h1>Hello <i>%s</i>!</h1>' % cgi.escape(form['user'].value))
by the logic if i enter user it must print
Hello user
. But it give’s
Who are you?
instead. It means that script doesn’t see user in the form. Why?
Cgi/py script is allowed in apache for cgi-bin/.
You have a typo here:
This should actually look like this:
type and name are each attributes on the input HTML tag. The form they will always be in is:
Please note the position of the quotes and equals signs. A good text editor that does syntax highlighting will help your eyeballs see this more clearly.