473,724 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transfer data from webpage form to database

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.

If any can help me I will be more than pleased... thanks for your help...

<html>

<head>

<title> Adminperson </title>

</head>

<body bgcolor="#0479f f">

<h1><p align="center"> Insert Person</h1></p>

<hr>

<form action="default .asp" method="post">
<p>Name:<br><in put 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>Adresse:<br> <input type="text" name="adresse"> </p>
<p>Zipcode:<br> <input type="text" name="zipcode"> </p>
<p>City:<br><in put type="text" name="city"></p>
<p>Phone:<br><i nput type="text" name="phone"></p
<p>Mail:<br><in put type="text" name="mail"></p>
<p> What is your profession? <p>
<INPUT TYPE=CHECKBOX NAME="Professio n" VALUE="Student" CHECKED> Student
<INPUT TYPE=CHECKBOX NAME="Professio n" VALUE="Teacher" CHECKED> Teacher
<INPUT TYPE=CHECKBOX NAME="Professio n" VALUE="Teacher Assistent" CHECKED>
Teacher Assistent
<p><input type="submit" value="Submit"> </p>
</body> </html>


Jul 18 '05 #1
12 6135
"Pete....." <he********@yah oo.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.FieldStorag e()

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/
Jul 18 '05 #2
Hi, yeah It's try I want to change it to a python.cgi.scri pt. And thanks for
your input.....

I use the api pgsql
So the first thing I do is to import the following and connect to the
server:

#!/pack/python-2.3.2/bin/python2.3
from pyPgSQL import PgSQL
import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorag e() ( I added this )
connect = PgSQL.connect(u ser="vvvvv", password="zzzzz ", host="xxx.xxx.x x",
database="yyyyy ")

Do I then have to write:

PgSQL.query(''' INSERT into form
Select persons.idperso ns, person.username ,
persons.surname , phone.phone (And so on ) ( its what the specific tables
are called in my database)
From persons, phone (
And so on )
Where persons.name = 'Name'%s
AND persons.surname ='Surname'%s
AND persons.usernam e = 'Username'%s '''
(And so on with the rest)
% (form['name'].value, form['surname'].value,
form['username'].value))

I dont think I get it quite right, any help would be highly appreciated.
Thanks for all help...
Below is the code from my webpage form:

<form action="default .asp" method="post">
<p>Name:<br><in put type="text" name="name"></p>
<p>Surname:<br> <input type="text" name="surnavn"> </p>
<p>Username:<br ><input type="text" name="username" ></p>
<p>Password:<br ><input type="text" name="password" ></p>
<p>Adresse:<br> <input type="text" name="adresse"> </p>
<p>Zipcode:<br> <input type="text" name="zipcode"> </p>
<p>City:<br><in put type="text" name="city"></p>
<p>Phone:<br><i nput type="text" name="phone"></p
<p>Mail:<br><in put type="text" name="mail"></p>
<p> What is your profession? <p>
<INPUT TYPE=CHECKBOX NAME="Professio n" VALUE="Student" CHECKED> Student
<INPUT TYPE=CHECKBOX NAME="Professio n" VALUE="Teacher" CHECKED> Teacher
<INPUT TYPE=CHECKBOX NAME="Professio n" VALUE="Teacher Assistent"
CHECKED> Teacher Assistent
<p><input type="submit" value="Submit"> </p>
</body> </html>'''

Jul 18 '05 #3
"Pete....." <he********@yah oo.com> writes:
Hi, yeah It's try I want to change it to a python.cgi.scri pt. And thanks for
your input.....

I use the api pgsql
So the first thing I do is to import the following and connect to the
server:

#!/pack/python-2.3.2/bin/python2.3
from pyPgSQL import PgSQL
import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorag e() ( I added this )
connect = PgSQL.connect(u ser="vvvvv", password="zzzzz ", host="xxx.xxx.x x",
database="yyyyy ")

Do I then have to write:

PgSQL.query(''' INSERT into form
Select persons.idperso ns, person.username ,
persons.surname , phone.phone (And so on ) ( its what the specific tables
are called in my database)
From persons, phone (
And so on )
Where persons.name = 'Name'%s
AND persons.surname ='Surname'%s
AND persons.usernam e = 'Username'%s '''
(And so on with the rest)
% (form['name'].value, form['surname'].value,
form['username'].value))

I dont think I get it quite right, any help would be highly appreciated.
Thanks for all help...


It looks to me like the part here that you don't understand is how to
interpolate your form data into the string for the database query.

You should study up on the % string formatting operator in the Python
docs.

I'll throw you a bone here;

"""
%s %s %s
""" % (form[key1].value, form[key2].value, form[keyN].value)

Each of those %s tokens is going to be replaced with one of the values
in the tuple right of the % operator.

If you want to pile the form values into a dict and then use symbolic
names in the string...

dict = {}
for key in form:
dict[key] = form[key].value

"""
%(key1)s %(key2)s...
""" % dict

Maybe there is a function in the cgi module that will make the dict
for you? I am not sure.

Have fun!
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 18 '05 #4
Hi again and thanks.
I think I understand the meaning of string formatting operators, I also
understand the meaning with % (form['name'].value, form['surname'].value,
form['username'].value)) And that it is a dictionary that I use.

The thing I find really hard to understand is how I can send the data from
the webform to my postgresql database. I cant find the right commands, i
been searching the web for days now without luck.

PgSQL.query(''' INSERT into form Select persons.idperso ns, person.username ,
persons.surname , phone.phone (And so on ) ( its what the specific tables is
called in my db)
From persons, phone( And so on )
Where persons.name = 'Name'%s
AND persons.surname ='Surname'%s
AND persons.usernam e = 'Username'%s ''' (And so on with the rest)

I dont really know if I have to write Pgsql.query("IN SERT into form
............... ..........
or if I have to write something else.
I know that I have to take the input from my webform, and store each input
( with each input I mean what the user types in each field, could be the
name, the username etc) in a "variable" so that I can put it into the right
place in the db.
I can see that I do this by using % (form['name'].value,
form['surname'].value, form['username'].value))
But I dont know how I put the data form['name].value in to my database in
the table persons.name.

Sorry for all this questions, just getting really confused with this little
project of mine, thinks its fun, but I just cant figure it out anymore, and
I cant find any info I can use on the web....

Thanks for taking your time to read this....
"Jerry Sievers" <je***@jerrysie vers.com> wrote in message
news:m3******** ****@prod01.jer rysievers.com.. .
"Pete....." <he********@yah oo.com> writes:
Hi, yeah It's try I want to change it to a python.cgi.scri pt. And thanks
for
your input.....

I use the api pgsql
So the first thing I do is to import the following and connect to the
server:

#!/pack/python-2.3.2/bin/python2.3
from pyPgSQL import PgSQL
import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorag e() ( I added this )
connect = PgSQL.connect(u ser="vvvvv", password="zzzzz ",
host="xxx.xxx.x x",
database="yyyyy ")

Do I then have to write:

PgSQL.query(''' INSERT into form
Select persons.idperso ns, person.username ,
persons.surname , phone.phone (And so on ) ( its what the specific tables
are called in my database)
From persons, phone
(
And so on )
Where persons.name = 'Name'%s
AND persons.surname ='Surname'%s
AND persons.usernam e = 'Username'%s '''
(And so on with the rest)
% (form['name'].value, form['surname'].value,
form['username'].value))

I dont think I get it quite right, any help would be highly appreciated.
Thanks for all help...


It looks to me like the part here that you don't understand is how to
interpolate your form data into the string for the database query.

You should study up on the % string formatting operator in the Python
docs.

I'll throw you a bone here;

"""
%s %s %s
""" % (form[key1].value, form[key2].value, form[keyN].value)

Each of those %s tokens is going to be replaced with one of the values
in the tuple right of the % operator.

If you want to pile the form values into a dict and then use symbolic
names in the string...

dict = {}
for key in form:
dict[key] = form[key].value

"""
%(key1)s %(key2)s...
""" % dict

Maybe there is a function in the cgi module that will make the dict
for you? I am not sure.

Have fun!
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/

Jul 18 '05 #5
[Pete]
[snip]
Below is the code from my webpage form:

<form action="default .asp" method="post">


You should note that the action attribute of a form must contain the URL
to which the form variables will be POSTed.

If you are writing a python CGI script, then action="default .asp" is
almost certainly wrong, unless you have called your python script
"default.as p".

The URL for your python script is the value that should go in the action
attribute, like so

<form action="http://mydomain.com/cgi-bin/my_cgi_script.p y" method="post">

or you could leave out the server name bit.

<form action="/cgi-bin/my_cgi_script.p y" method="post">

HTH,

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
Jul 18 '05 #6
"Pete....." <he********@yah oo.com> writes:
Hi again and thanks.
I think I understand the meaning of string formatting operators, I also
understand the meaning with % (form['name'].value, form['surname'].value,
form['username'].value)) And that it is a dictionary that I use.

The thing I find really hard to understand is how I can send the data from
the webform to my postgresql database. I cant find the right commands, i
been searching the web for days now without luck.

PgSQL.query(''' INSERT into form Select persons.idperso ns, person.username ,


You mean that whatever docs for the PgAPI that you are using don't
explain?

I am using pygresql. There are others.

from pgdb import connect

conn = connect(databas e = 'db', username = 'user', password = 'passwd')
cursor = conn.cursor()

cursor.execute( "insert into foo values (1)")
conn.commit()

That's about all the help I can give you.

Good luck

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 18 '05 #7
Pete,
What you're looking for is an INSERT SQL query. You can find the basic
theory and some more advanced bits 'n pieces here (specifically
PostgreSQL):

http://www.commandprompt.com/ppbook/...ap=x5504%2ehtm

The question that you're asking is so vague that you should think about
reading up on SQL before going any further - you may find yourself
quickly overwhelmed otherwise.

Andrew

On Tue, 2004-11-23 at 20:43 +0000, Alan Kennedy wrote:
[Pete]
> [snip]
> Below is the code from my webpage form:
>
> <form action="default .asp" method="post">


You should note that the action attribute of a form must contain the URL
to which the form variables will be POSTed.

If you are writing a python CGI script, then action="default .asp" is
almost certainly wrong, unless you have called your python script
"default.as p".

The URL for your python script is the value that should go in the action
attribute, like so

<form action="http://mydomain.com/cgi-bin/my_cgi_script.p y" method="post">

or you could leave out the server name bit.

<form action="/cgi-bin/my_cgi_script.p y" method="post">

HTH,

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan

--
Andrew James <dr**@gremlinho sting.com>

Jul 18 '05 #8
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.FieldStorag e()

connect = PgSQL.connect(u ser="user", password="passw ord", host="host",
database="datab ase")
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="#0479f f">

<h1><p align="center"> Insert Person</h1></p>

<hr>

<form action="inserti ntotable.py" method="get">
<p>Name:<br><in put 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...
Jul 18 '05 #9
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="inserti ntotable.py" method="get">
<p>Name:<br><in put type="text" name="name"></p>

Any ideas ?
Thanks all

"Pete....." <he********@yah oo.com> wrote in message
news:41******** *************** @nntp06.dk.teli a.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.FieldStorag e()

connect = PgSQL.connect(u ser="user", password="passw ord", host="host",
database="datab ase")
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="#0479f f">

<h1><p align="center"> Insert Person</h1></p>

<hr>

<form action="inserti ntotable.py" method="get">
<p>Name:<br><in put 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...

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1176
by: Andrew | last post by:
Can someone out there help. I am using Server. Transfer from a user control to a webform and tried to follow many examples exactly as specified but cannot get around the (Specified cast is not valid.) ERROR which happens on the second page Search.aspx on the line with (PrevPageValues = (FirstPage)Context.Handler;). I have also got <%@ Reference Page="_FirstPage.ascx" %> at the top of the second page.
2
1648
by: Jeremy | last post by:
I'm having some problems with using Server.Transfer and I am hoping somebody can help me. Page 1 has a datagrid, Page 2 has a form. If a user goes to page 1 and selects something out of the datagrid I want to transfer the value of that records item number in the grid over to page 2. I use the passed number to retrieve data from a database and populate the form.
11
6041
by: Alexander Bosch | last post by:
Hi, I'm having a problem similar to the one that's stated in this KB http://support.microsoft.com/default.aspx?scid=kb;en-us;839521 When I'm posting a page to itself with the bool value as true it falls into an infinite loop and later a StackOverflow Exception. I need to do this and not a Response.Redirect or a transfer with the bool in false. My problem is that this KB is saying that this problem should be solved with ServicePack 1 of...
1
1611
by: Michael | last post by:
I am using Visual Studio 2005 (ASP 2.0) to build a webpage that uses a Microsoft Access Database. The data in the database simply holds the information on a link to a document that I am storing on the website. The information is written into the webpage dynamically. That way when I add documents, I only have to update the database and not mess with the page itself. I am using AccessDataSource to link to the database. I first linked...
6
2875
by: shivavrata | last post by:
Hi All, I want to transfer the data form webpage to any other own application which is running in backend.How i develop this web page. which technology is good for this or any particular protocol i have to use for this. Please suggest if any idea regarding data transfer. Thanks Shiva Vrata Anand
3
4115
by: JohnM | last post by:
I can transfer from a query with DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Filenam", CPath, True I would like to use a form for the user to select and order data then export th result. How do I set about this?
9
2080
by: Bob Alston | last post by:
I have been trying to make sure my transfer of data from BE to FE is the lowest possible. I found this info in a web posting by Pat Partman, a MVP, here http://72.14.203.104/search?q=cache:hcfSexNmSEEJ:www.access-programmers.co.uk/forums/showthread.php%3Ft%3D46496+access+form+query+where+clause+what+data+from+backend&hl=en&ct=clnk&cd=4&gl=us Please verify that I have it correct: 1) A Form filter set in a form that has a record...
2
3577
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information from the database and allow the user to update the database using the web page' stage and realized...
2
3115
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi, I'm using Threads, and when I try to do Server.Transfer, I recieved an error. (child object does not exist...) My Code: Dim t As New Thread(AddressOf Hilo) Private Sub Hilo() Thread.Sleep(1000)
0
8868
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8062
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3209
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2612
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2149
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.