Transfer data from webpage form to database
Pete.....
helten0007 at yahoo.com
Tue Nov 23 19:52:05 EST 2004
The error I get is that when this code starts: %(form[name].value,
form[surname].value, form[username].value, form[password].value)
it says that NameError: name 'name' is not defined
args = ("name 'nama' is not defined",)
which is from the html webpage form code
form action="insertintotable.py" method="get">
<p>Name:<br><input type="text" name="name"></p>
Any ideas ?
Thanks all
"Pete....." <helten0007 at yahoo.com> wrote in message
news:41a3ccf2$0$29450$ba624c82 at nntp06.dk.telia.net...
> First thanks for all your friendly input and for looking at this once
> again...
>
> I think I made some progress, but its still not working, so I must still
> do something wrong.
> Here is how far I have come.
>
> I made an insertintotable script, that I want to run every time a person
> presses "The submit button on my webpage" It goes like this:
> --------------------------------------------------------------------
> #!/pack/python-2.3.2/bin/python2.3
>
> from pyPgSQL import PgSQL
> import cgi
> import cgitb
> cgitb.enable()
>
> form = cgi.FieldStorage()
>
> connect = PgSQL.connect(user="user", password="password", host="host",
> database="database")
> cur = connect.cursor()
> cur.execute('''INSERT INTO persons (name, surname, username, password)
> (VALUES(%s,%s, %s, %s)''')
> %(form[name].value, form[surname].value, form[username].value,
> form[password].value)
> ---------------------------------------------------------------------------------------------
> My question is, do I need more code to tell the program that I want to
> transfer the user input ( on my webpage ) to my postgresql database.
> ---------------------------------------------------------------------------
> The code from my webpage is:
>
> #!/pack/python-2.3.2/bin/python2.3
>
> from pyPgSQL import PgSQL
> import cgi
> import cgitb
> cgitb.enable()
>
> print '''
>
> <html>
>
> <head>
>
> <title> Adminperson </title>
>
> </head>
>
> <body bgcolor="#0479ff">
>
> <h1><p align="center">Insert Person</h1></p>
>
> <hr>
>
> <form action="insertintotable.py" method="get">
> <p>Name:<br><input type="text" name="name"></p>
> <p>Surname:<br><input type="text" name="surnavn"></p>
> <p>Username:<br><input type="text" name="usernavn"></p>
> <p>Password:<br><input type="text" name="password"></p>
> <p><input type="submit" value="Submit"></p>
> </body> </html>'''
> ------------------------------------------------------------------------
> And once again thanks...
>
More information about the Python-list
mailing list