Transfer data from webpage form to database

Pete..... helten0007 at yahoo.com
Tue Nov 23 19:03:13 EST 2004


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