jameskane
asked on
Python 3.4 - passing variable values to CGI page via URL
I have a table of member information as shown below. Users click on a selected name and it is necessary that the selected memberID be sent to another page nextpage.cgi. See from the image that the names column is url active and clicking will send a url localhost/office_15/nextpa ge.cgi?mem berID=1215 13 from this page to nextpage.cgi. This works as I can see from the pointer address over the active link
My problem is with the action page nextpage.cgi which is not processing the url correctly. I get the following error. I am attaching the nextpage.cgi code. Appreciate if someone could take a look at it.
Many thanks
My problem is with the action page nextpage.cgi which is not processing the url correctly. I get the following error. I am attaching the nextpage.cgi code. Appreciate if someone could take a look at it.
Many thanks
Traceback (most recent call last):
File "C:/xampp2/htdocs/OFFICE_15/NEXTPAGE.cgi", line 29, in <module>
print(memberId[0])
NameError: name 'memberId' is not defined
#!C:\Python34\python.exe
import cgi,cgitb
def htmlTop():
print("""Content-type:text/html\n\n
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title> My Server-side template</title>
</head>
<body>""")
def htmlTail():
print(""" its done</body>
</html>""")
def getData():
form = cgi.FieldStorage()
memberId = form.getvalue('memberId')
memberId = memberId[0]
return memberId
#main program
if __name__== "__main__":
try:
htmlTop()
print(memberId[0])
htmlTail()
except:
cgi.print_exception()
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome, glad to help.
ASKER
million thanks for taking the time on my problem. THE problem which caused me grief turns out to be the spelling - which I was careless about as I did not think CAPITALIZATION mattered !!!!! In my sql table I named the table column memberID. Then in the page proceeding the one in question I used memberId. Then finally in the problem page I have been using a mixture without thinking about it .
The page I put up had (by chance) consistent spelling - but in my messing about I forgot to include the GetData() function (which I had been using in previous attempts)
Turns out the error message is the same for both !!
I have now tidied all this up and also integrated the points you made Mark. All is now well !!
thanks again to you both.