当前位置: 移动技术网 > IT编程>开发语言>.net > 创建一个Web投票系统

创建一个Web投票系统

2018年10月15日  | 移动技术网IT编程  | 我要评论

武装风暴5200,在家可以做什么兼职,qq积分兑换红钻

下面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)};"

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网