We help IT Professionals succeed at work.
Get Started

Python 3.4  - passing  variable values to CGI page via URL

jameskane
jameskane asked
on
330 Views
Last Modified: 2015-04-11
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/nextpage.cgi?memberID=121513 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


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

Open in new window


#!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()

Open in new window



Table with url active links
Comment
Watch Question
Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE