将数据从网页表单传输到数据库 [英] Transfer data from webpage form to database

查看:112
本文介绍了将数据从网页表单传输到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我已经制作了一个网页,其中有一个网页形式,人们可以填写

他们的个人信息:


代码如下:

我想将数据传输到postgreSQL数据库(我已经使用必要的表格已经制作了数据库,我知道如何连接到它)

但我真的不知道如何将数据从webform传输到数据库的



如果有任何可以帮助我的话,我会非常高兴...感谢您的帮助...


< html>


< head>


< title>管理员< / title>


< / head>


< body bgcolor ="#0479ff">


< h1>< p align =" center">插入人< / h1>< / p>


< hr> ;


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

< p>名称:< br>< input type =" text" name =" name">< / p>

< p>姓:< br>< input type =" text" name =" surnavn">< / p>

< p>用户名:< br>< input type =" text" name =" usernavn">< / p>

< p>密码:< 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>< input type =" text" name =" city">< / p>

< p>电话:< br>< input type =" text" name =" phone">< / p

< p> Mail:< br>< input type =" text" name =" mail">< / p>

< p>你的专业是什么? < p>

< INPUT TYPE = CHECKBOX NAME =" Profession" VALUE ="学生" CHECKED>学生

< INPUT TYPE = CHECKBOX NAME =" Profession" VALUE ="教师" CHECKED>老师

< INPUT TYPE = CHECKBOX NAME =" Profession" VALUE =教师助理已检查>

教师助理

< p>< input type =" submit" value =" Submit">< / p>

< / body> < / html>

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="#0479ff">

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

<hr>

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


推荐答案

" Pete ..... <他******** @ yahoo.com>写道:
"Pete....." <he********@yahoo.com> writes:
大家好。
我创建了一个网页,其中有一个网页表格,人们可以填写他们的个人信息:

我想将数据传输到postgreSQL数据库(我已经用必要的表创建了数据库,我知道如何连接它)
但我真的不知道如何将数据从webform传输到数据库。
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.




您的示例表单显示被发布到你要去的ASP文件

改成Python.cgi脚本吧?


#!/ usr / local / bin / python


print''content-type:text / plain\\\
''

import cgi

import someDatabaseAPI


form = cgi.FieldStorage()


someDatabaseAPI.connect()

someDatabaseAPI.query ("""

插入foo

值(''%s''' ,''%s'')

""" %(表单[key1] .value,表单[key2] .value))


#其中key1,key2 ...是HTML表单中的字段名称


看一下cgi Python模块,你将学到所有关于

这个。


HTH

-

--------------------------------------- ----------------------------------------

Jerry Sievers 305 854-3001(主页)WWW电子商务顾问

305 321-1144(手机 http://www.JerrySievers.com/


是的,我想尝试将其更改为python.cgi.script感谢

您的输入.....


我使用api pgsql

所以我做的第一件事是导入以下内容并连接到

服务器:

#!/ pack / python-2.3.2 / bin / python2.3
来自pyPgSQL导入PgSQL

导入cgi

导入cgitb

cgitb.enable()


form = cgi.FieldStorage()(我添加了这个)

connect = PgSQL.connect(user =" vvvvv",password =" zzzzz", host =" xxx.xxx.xx",

database =" yyyyy")


我是否必须写:


PgSQL.query('''''插入表格

选择persons.idpersons,person.username,

persons.surname,phone .phone(依此类推)(它的具体表格

在我的数据库中被调用)

来自人,电话(

等等on)

其中,person.name =''姓名''%s

AND persons.surname =''姓氏''%s

AND persons.username =''用户名''%s''''''

(依此类推)

%(表格[''name' '] .value,form [''surname'']。value,

form [''username'']。value))


我不我觉得我说的很对,任何帮助都会很高hly赞赏。

感谢所有帮助...

以下是我的网页表格中的代码:


<表格行动= QUOT;&Default.asp的QUOT; method =" post">

< p>名称:< br>< input type =" text" name =" name">< / p>

< p>姓:< br>< input type =" text" name =" surnavn">< / p>

< p>用户名:< br>< input type =" text" name =" username">< / p>

< p>密码:< 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>< input type =" text" name =" city">< / p>

< p>电话:< br>< input type =" text" name =" phone">< / p

< p> Mail:< br>< input type =" text" name =" mail">< / p>

< p>你的专业是什么? < p>

< INPUT TYPE = CHECKBOX NAME =" Profession" VALUE ="学生" CHECKED>学生

< INPUT TYPE = CHECKBOX NAME =" Profession" VALUE ="教师" CHECKED>老师

< INPUT TYPE = CHECKBOX NAME =" Profession" VALUE =教师助理

CHECKED>老师助理

< p>< input type =" submit" value =" Submit">< / p>

< / body> < / html>'''''

Hi, yeah It''s try I want to change it to a python.cgi.script. 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.FieldStorage() ( I added this )
connect = PgSQL.connect(user="vvvvv", password="zzzzz", host="xxx.xxx.xx",
database="yyyyy")

Do I then have to write:

PgSQL.query('''''' INSERT into form
Select persons.idpersons, 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.username = ''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><input 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><input type="text" name="city"></p>
<p>Phone:<br><input type="text" name="phone"></p
<p>Mail:<br><input type="text" name="mail"></p>
<p> What is your profession? <p>
<INPUT TYPE=CHECKBOX NAME="Profession" VALUE="Student" CHECKED> Student
<INPUT TYPE=CHECKBOX NAME="Profession" VALUE="Teacher" CHECKED> Teacher
<INPUT TYPE=CHECKBOX NAME="Profession" VALUE="Teacher Assistent"
CHECKED> Teacher Assistent
<p><input type="submit" value="Submit"></p>
</body> </html>''''''


" Pete ..... <他******** @ yahoo.com>写道:
"Pete....." <he********@yahoo.com> writes:
是的,我试着把它改成python.cgi.script。感谢您的输入.....

我使用api pgsql
所以我做的第一件事就是导入以下内容并连接到
服务器:

#!/ pack / python-2.3.2 / bin / python2.3
来自pyPgSQL导入PgSQL
导入cgi
导入cgitb
cgitb.enable()

form = cgi.FieldStorage()(我添加了这个)
connect = PgSQL.connect(user =" vvvvv",password =" zzzzz",host =" xxx.xxx.xx",
database =" yyyyy")

然后我必须写:

PgSQL.query('' ''''插入表单
选择persons.idpersons,person.username,
persons.surname,phone.phone(依此类推)(它的具体表格在我的名字中被调用)数据库)
来自人,电话(
等)
其中persons.name =''姓名''%s
AND persons.surnam e =''姓氏''%s
AND persons.username =''用户名''%s''''''
(等等其余部分)
%(表格) [''name'']。value,form [''surname'']。value,
form [''username'']。value))

我不认为我得到非常正确,任何帮助都将受到高度赞赏。
感谢您的帮助...
Hi, yeah It''s try I want to change it to a python.cgi.script. 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.FieldStorage() ( I added this )
connect = PgSQL.connect(user="vvvvv", password="zzzzz", host="xxx.xxx.xx",
database="yyyyy")

Do I then have to write:

PgSQL.query('''''' INSERT into form
Select persons.idpersons, 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.username = ''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...




在我看来,这就像你在这里的部分一样我不明白如何将
插入表格数据到数据库查询的字符串中。


你应该研究一下%字符串格式化操作符Python

docs。


我会在这里扔你的骨头;


""" ;

%s%s%s

""" %(表单[key1] .value,表单[key2] .value,表单[keyN] .value)


每个%s标记将被替换为其中一个在%运算符的元组右边的值



如果你想将表单值堆积到一个字典中然后使用符号

字符串中的名字......


dict = {}

表格中的密钥:

dict [key ] = form [key] .value


""

%(key1)s%(key2)s ...

""" %dict


也许cgi模块中有一个函数可以为你制作字典

?我不确定。


玩得开心!

-

------------ -------------------------------------------------- -----------------

Jerry Sievers 305 854-3001(主页)WWW电子商务顾问

305 321-1144(移动 http://www.JerrySievers.com/


这篇关于将数据从网页表单传输到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆