创建一个Web投票系统
程序员文章站
2022-07-02 15:35:39
下面zip文件:dir.co.uk/files/article-11.zip>https://www.content.aspdir.co.uk/files/article-11.zipduring...
下面zip文件:dir.co.uk/files/article-11.zip>https://www.content.aspdir.co.uk/files/article-11.zip
during this article you will learn how to construct your own web poll using asp. the article presumes you
already understand basic database interaction.
the following samples of code allow a user to select one of four options to a question. the users vote is
then recorded in a database and the user is taken to a page where the results for each option can be
viewed in statistical, numerical and graphical form. not bad, huh?
the whole application is based on the database itself, so when the values within the database are altered,
the application automatically changes. the database design itself, is not included within this article so
make sure to download a copy of the entire application, including the database before running the code.
the code for the first page is shown as follows: -
page: default.asp
<%
connects to database using recordset method
function dataconn(database,connection,recordset)
set connection = server.createobject("adodb.connection")
set recordset = server.createobject("adodb.recordset")
connection.open "dbq=" & server.mappath(database) & ";driver={microsoft access(小型网站之最爱) driver (*.mdb)};"
end function
%>
<html>
<head>
<title>poll example</title>
</head>
<body>
<form name="languages" method=post action="pollresults.asp">
<p>what is your favoutrite language?</p>
<%
calls dataconn function to open dbpoll.mdb
dataconn "files/dbpoll.mdb",podc,lars
selects all fields within tbllanguages
lars.open "select * from tbllanguages", podc
loop through and display each record within the database as a radio button
do while not lars.eof
response.write lars("language") & ": <input type=radio name=language value=" & lars("language")
& "><br>"
lars.movenext
loop
close database connection
lars.close
podc.close
set podc = nothing
%>
<a href="pollresults.asp">view poll</a>
<input type=submit value="vote">
</form>
</body>
</html>
once connected to the database the script loops through each record, and displays that option as a radio
button. when the vote button is pressed, the inpidual value of the selected radio button is submitted
to the next page.
the code for the next page is shown below: -
page: pollresults.asp
<%
define all variables that will be used
dim i, percent
connects to database using recordset method
function dataconn(database,connection,recordset)
set connection = server.createobject("adodb.connection")
set recordset = server.createobject("adodb.recordset")
connection.open "dbq=" & server.mappath(database) & ";driver={microsoft access(小型网站之最爱) driver (*.mdb)};"
during this article you will learn how to construct your own web poll using asp. the article presumes you
already understand basic database interaction.
the following samples of code allow a user to select one of four options to a question. the users vote is
then recorded in a database and the user is taken to a page where the results for each option can be
viewed in statistical, numerical and graphical form. not bad, huh?
the whole application is based on the database itself, so when the values within the database are altered,
the application automatically changes. the database design itself, is not included within this article so
make sure to download a copy of the entire application, including the database before running the code.
the code for the first page is shown as follows: -
page: default.asp
<%
connects to database using recordset method
function dataconn(database,connection,recordset)
set connection = server.createobject("adodb.connection")
set recordset = server.createobject("adodb.recordset")
connection.open "dbq=" & server.mappath(database) & ";driver={microsoft access(小型网站之最爱) driver (*.mdb)};"
end function
%>
<html>
<head>
<title>poll example</title>
</head>
<body>
<form name="languages" method=post action="pollresults.asp">
<p>what is your favoutrite language?</p>
<%
calls dataconn function to open dbpoll.mdb
dataconn "files/dbpoll.mdb",podc,lars
selects all fields within tbllanguages
lars.open "select * from tbllanguages", podc
loop through and display each record within the database as a radio button
do while not lars.eof
response.write lars("language") & ": <input type=radio name=language value=" & lars("language")
& "><br>"
lars.movenext
loop
close database connection
lars.close
podc.close
set podc = nothing
%>
<a href="pollresults.asp">view poll</a>
<input type=submit value="vote">
</form>
</body>
</html>
once connected to the database the script loops through each record, and displays that option as a radio
button. when the vote button is pressed, the inpidual value of the selected radio button is submitted
to the next page.
the code for the next page is shown below: -
page: pollresults.asp
<%
define all variables that will be used
dim i, percent
connects to database using recordset method
function dataconn(database,connection,recordset)
set connection = server.createobject("adodb.connection")
set recordset = server.createobject("adodb.recordset")
connection.open "dbq=" & server.mappath(database) & ";driver={microsoft access(小型网站之最爱) driver (*.mdb)};"
上一篇: ASP+配置 — ASP+配置概念(一)
下一篇: ASP实现简单的网页保护
推荐阅读
-
创建一个完整的ASP.NET Web API项目
-
用Eclipse 创建一个简单的web项目(图文教程)
-
用Eclipse 创建一个简单的web项目(图文教程)
-
创建一个完整的ASP.NET Web API项目
-
新版本IntelliJ IDEA 构建maven,并用Maven创建一个web项目(图文教程)
-
笔记本重做系统如何创建分区 给硬盘新建一个分区的方法介绍(图文教程)
-
Linux上为你的任务创建一个自定义的系统托盘指示器
-
Linux系统下怎么用CheckInstall从源码创建一个RPM或DEB包
-
C#创建一个小型Web Server(Socket实现)
-
新版本IntelliJ IDEA 构建maven,并用Maven创建一个web项目(图文教程)