创建一个Web投票系统
程序员文章站
2022-03-10 15:05:14
下面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)};"
上一篇: 有一个非常残酷的事实,未来80%的岗位将面临失业,准备好吗
下一篇: iOS开发可以用到的mac命令
推荐阅读
-
新版本IntelliJ IDEA 构建maven,并用Maven创建一个web项目(图文教程)
-
nodejs使用express创建一个简单web应用
-
带你使用Visual Studio 2019创建一个MVC Web应用
-
IDEA怎么创建一个静态web项目? IDEA新建web项目的技巧
-
JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识
-
笔记本重做系统如何创建分区 给硬盘新建一个分区的方法介绍(图文教程)
-
一个投票系统的源程序(coveryourasp.com)
-
web前端进阶02:初学nodeJS之http系统模块使用 (写一个http请求的服务器)
-
使用pycharm开发web——django2.1.5(二)创建一个app并做一些配置
-
eclipse入门之创建第一个web程序(jsp测试环境)