Transfer data from webpage form to database
Jerry Sievers
jerry at jerrysievers.com
Tue Nov 23 12:54:34 EST 2004
"Pete....." <helten0007 at yahoo.com> writes:
> Hi all.
> I have made a webpage where there is a webform where people can fill in
> their personel information:
>
> The code is below:
>
>
> I want to transfer the data to a postgreSQL database ( I have allready made
> the database with the neccesary tables, and I know how to connect to it )
> but I really have no idea how I can transfer the data from the webform to
> the database.
Your sample form shows being posted to an ASP file which you are going
to change to a Python.cgi script, right?
#!/usr/local/bin/python
print 'content-type: text/plain\n'
import cgi
import someDatabaseAPI
form = cgi.FieldStorage()
someDatabaseAPI.connect()
someDatabaseAPI.query("""
insert into foo
values ('%s', '%s')
""" % (form[key1].value, form[key2].value))
# where key1, key2... are the field names in HTML form
Have a look at the cgi Python module where you will learn all about
this.
HTH
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
More information about the Python-list
mailing list