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/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>
NameError: name 'memberId' is not defined

Open in new window

import cgi,cgitb

def htmlTop():
        <!DOCTYPE html>
        <html lang="en">
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>

def htmlTail():
    print(""" its done</body>

def getData():
    form = cgi.FieldStorage()
    memberId = form.getvalue('memberId')
    memberId = memberId[0]
    return memberId

#main program
if __name__== "__main__":

Open in new window

Table with url active links
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BradyPrincipal Data EngineerCommented:
As I see it, the memberId is returned from your function getData() but you are never calling that function. Also you can shorten the code in the getData function by changiung line  21 from
memberId = memberId[0]


return memberId[0]

and remove the next line.

Now in line 29 change it from


to print getData()

Unless you need to use memberId elsewhere in your code. If so then do it like this.

memberId = getData()
print memberId

You should also use a try/accept and some checking in the getData method like so.

def getData():
    form = cgi.FieldStorage()

        memberId = form.getvalue('memberId')

        if memberId is None:
        return False;
        memberId = memberId[0]
        return memberId
        return False

Open in new window

Dave BaldwinFixer of ProblemsCommented:
I just noticed, you have spelled memberID 3 different ways and that may be the problem.  You have 'memberID', 'memberId', and 'member_ID'.  Probably only one of those will work.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jameskaneAuthor Commented:
Mark and Dave,
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.
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.