Establish your website's voting mechanism! [translation]

zhaozj2021-02-16  60

How to use ASP to establish a voting mechanism in your own website (1)

Translation

A very good ASP program for building your own voting system, everyone can read it carefully, as long as you understand the key technologies in the middle, you can build your own polling station on your own website. The document is consolidated very rush, I hope everyone can understand. Copyright: ASP Pollsversion 1.0Tipped Cow Development and Adrenalin Labs structure brief: ACCESS database design structure: poll main table Field Name: PollName, PollCreator, PollQuestion, Password, Choice1, Choice2Choice3, Choice4, Choice5, ID (automatic number), GetNamepollresults Table field: Pollid, Pollaanswer, Name1. File db.inc <% Application ("ASP_POLL") = "ASP_POLL" CNSTRING = "Driver = {Microsoft Access Driver (* .mdb)};" cnstring = cnstring & "dbq =" & Server.mappath ("Events.mdb") Application ("asppolldsn") = cnstring%> 1. File Creat_pol1.asp <% title = "Poll generator"%> <% = title%> </ title> </ head> <body> <div align =" left "> <img src =" ASP_POLL.GIF "Width = "231" Height = "90"> <br> Another Joint Product from <a href="http://www.ncws.com/tippycow"> Tipped COW Developments </a> and <a href = "http: //dstoflet.calweb.com">Adrenalin Labs </a> <br> <br> </ div> <center></p> <p><% Response.write "<font face = arial>" If Request ("ErrorMessage") <> "" TenResponse.write "<b> Error! </ B>" & request ("ErrorMessage" Elseresponse.write "please Complete the form below to beg, your ing. "End IF%></p> <p><br> <br> <table border = 2 cellspacing = 0 cellpadding = 0> <tr> <td> <form method = "post" action = "create_poll2.asp"> <table border = 0 cellspacing = 0 cellpadding = 10 Width = 500> <tr> <td colspan = 2 bgcolor = # 000000 align = center class = "bold2"> Enter Your name as the point creator </ td> <Tr> <tr> <td bgcolor = # ffffff Width = 25% class = "bold"> Poll Creator: </ td> <td bgcolor = # ffffff> <input type = "name =" value = "" "" "" "" ")%>" SIZE = 20 class = "input"> </ td> </ tr> </ table></p> <p></ td> </ tr> <tr> <td></p> <p><table border = 0 cellspacing = 0 cellpadding = 10 width = 500> <tr> <td colspan = 2 bgcolor = # 000000 align = center class = "bold2"> Create a password for your poll so that You can modify it at alaater Time </ td> </ tr> <tr> <td bgcolor = # ffffff width = 25% class = "bold"> poll admin password: </ td> <td bgcolor = # ffffff> <input type = "password" Name = "Value =" <% = Request ("password")%> "size = 10 maxLength = 10 maxSize = 10 class = input> </ td> </ tr> </ table></p> <p></ td> </ tr> <tr> <td></p> <p><table border = 0 cellspacing = 0 cellpadding = 10 width = 500> <tr> <td colspan = 2 bgcolor = # 000000 align = center class = "bold2"> give your poll a unique name </ td> </ tr> <tr> <td bgcolor = # ffffff width = 25% class = "bold"> poll name: </ td> <td bgcolor = # fffff> <input type = "text" name = "name" value = "<% = Request ("name")%> "size = 20 class = input> </ td> </ tr> </ table> <table border = 0 Cellspacing = 0 cellpadding = 10 width = 500> <tr> <td colspan = 2 bgcolor = # 000000 align = center class = "bold2"> Do you want to have to have the user enter their name? </ Td> </ tr> <tr> <td bgcolor = # ffffff width = 25% class = " Bold "> Require user to enter their name: </ td> <td bgcolor = # fffff Class =" bold "> yes <input type =" radio "name =" getname "value =" 1 "> <br> NO < INPUT TYPE = "Radio" name = "getname" value = "0" checkage> </ td> </ tr> </ table></p> <p></ td> </ tr> <tr> <td></p> <p><table border = 0 cellspacing = 0 cellpadding = 10 width = 500> <tr> <td colspan = 3 bgcolor = # 000000 align = center class = "bold2"> Select Poll Type </ td> </ tr> <TR></p> <p><td colspan = 2 bgcolor = # ffffff class = "bold"> What type of point questiondo you wish to create? </ td> <td bgcolor = # ffffff class = "bold"> <input type = "radio" name = "polltype" value = "yes_no"> YES / no <br> <input type = "radio" name = "polType" value = "multiple_choice"> multiple choice <br> </ td> </ tr> </ table> </ td> </ tr> </ table> <Table Width = 500> <Tr> <TD Colspan = 3 Align = Right> <input type = "submit" value = "next" class = "inline"> </ TD> </ tr> </ table> </ center> </ body> </ html> 3. File connect.asp <% id = request ("id") if id = "" THENID = 0END ifnum = request "kice") if Num <> "" "</p> <p>Set conn = server.createObject ("adodb.connection") DSNPATH = "driver = {Microsoft Access Driver (* .mdb)};" DSNPATH = DSNPATH & "DBQ =" & Server.MAppath ("events.mdb") conn .open dsnpathset = server.createObject ("adodb.recordset") RS.Open "PollResults", CONN, 3, 3RS.AddNewRs ("Pollid") = CINT (ID) = Request ("Name" ") RS (" Pollaanswer ") = cint (num) rs.Updaters.closset = Nothingconn.closset conn = Nothingend IF</p> <p>If Request ("Return_page") <> Empty ThenResponse.cookies ("Pollid") = idResponse.Redirect Request ("Return_Page") End IF%></p> <p><html> <body bgcolor = "# 4f4f4f" text = "# c0c0c0" link = # f5fcdc vLink = # f5fcdc> <center></p> <p><% If num <> "" Then%> <br> <br> <table border = 0 cellspacing = 0 cellpadding = 0> <tr> <td colspan = 3 align = center> <font face = "verdana"> Your Selection Has Been Record. </ TD> </ TR> </ Table></p> <p><% End If%> <br> <br> <%</p> <p>Set conn = server.createObject ("adodb.connection") SQL = "Select * from poll where id =" & cint (id) DSNPATH = "driver = {Microsoft Access Driver (* .mdb)};" DSNPATH = DSNPATH & "Dbq =" & server.mappath ("events.mdb") conn.open dsnpathset = conn.execute (sql) if = 0 Cellpadding = 5 width = 500 Bordercolor = # 2f2f4f> <tr> <TD colspan = 3 bgcolor = # 2f2f4f align = center> <font face = "verdana" color = # f5fcdc> <% = rs ("pollquestion")%> </ td> </ Tr> <% DIM Choices (6) Dim Responses (6) for i = 1 to 5choice = RS ("Choice" & i) Choices (i) = choiceif choice <> "" THENSET CONN2 = Server.createObject ("adoDB. Connection ") sql =" select COUNT (PollAnswer) from PollResults where PollID = "& Cint (id) &" AND PollAnswer = "& Idsnpath =" DRIVER = {MICROSOFT ACCESS DRIVER (* .mdb)}; "dsnpath = dsnpath & "Dbq =" & server.mappath ("events.mdb") conn2.open dsnpathset = conn.execute (SQL) if q = 5 <tr> <td colspan = 2 bgcolor = # 4f4f4f align = Center width = 400> <font face = verdana col OR = # f5fcdc> "response.write choiceresponse.write" </ td> "Response.write" <TD colspan = 1 bgcolor = # 4f4f4f align = right> <font face = Verdana Color = # f5fcdc> <b> "& r2 (0) &" </ b> </ td> "response.write" </ TR> "</p> <p>End ifrs2.closeconn2.closend ifnextend IF%> </ table></p> <p><br> <br></p> <p><Table> <TD COLSPAN = 3 Align = Center> <font face = "arial"> <font face = "ms sans serif"> <b> polls results </ b> </ font> </ td> </ tr ></p> <p><% Total = 0for i = 1 to 5Responsecount = Response (i) if Responsecount <> "" "" TENTAL = Total Cint (responsecount) end ifnextfor i = 1 to 5choice = choices (i) responsecount = response code (i) if Choice < > "" Tellonse.write "<tr> <td colspan = 1 align = left> <font face = arial>" response.write choicesPonse.write "</ td>" response.write <TD colSpan = 2 width = 400 > <table border = 1 cellspacing = 0> <tr> <td bgcolor = blue align = center width = "& converttopix (responsecount) &"> <font face = ms Sans Serif color = White> <b> "& converttopercent ( Responsecount) & "</ td> </ tr> </ table> </ td>" response.write "</ tr>" end ifnext</p> <p>Function ConvertTopix (SZ) IF SZ = 0 ThenConvertTopix = 0ELSECONVERTTTOPIX = CINT (400 / Total * SZ) End IFEND Function</p> <p>Function ConvertTopercent (SZ) IF SZ = 0 ThenconvertTopercent = "0%" ElseconvertTopercent = Formatpercent (SZ / Total, 2) End IFEND FUNCTION</p> <p>%></p> <p></ TABLE></p> <p><% If num = "" Then%> <br> <br> <table border = 0 cellspacing = 0 cellpadding = 0> <tr></p> <p><TD colspan = 3 align = center> <font face = "verdana"> <a href="default.asp?id=< %=id%> Add your vote </a> </ td> </ tr > </ TABLE> <% END IF%></p> <p><br> <Table Width = 100%> <Tr> <TD Align = Right> <Table Border = 1 Cellpadding = 5 Cellspacing = 0 BorderColor = # f5fcdc> <Tr> <TD BGColor = # 2f2f4f> <font Face = verdana size = 1> <a href=javascript:History.Back ()> back </a> </ td> </ tr> </ table> </ td> </ tr> </ table></p> <p></ center> </ body> </ html> -------------------------------------- -----------</p> <p>How to use ASP to establish a voting mechanism in your own website (2)</p> <p>Translation</p> <p>4, file default.asp <% id = request ("ID") if id = "" "" "" "= 30nd iftitle =" Polls (Create Your Own Poll) "%></p> <p><html></p> <p><head> <link rel = "stylesheet" type = "text / css" href = "style.css"> <title> ASP POLLS </ TITLE></p> <p><script language = "javascript"></p> <p>Function Gatherform (Form) {if (form.mode [0] .checked) {form.submit ();} else {form.Action = "collect.asp"; form.submit ();}}</p> <p></ script> </ hEAD></p> <p><body> <div align = "left"> <img src = "ASP_POLL.GIF" width = "231" height = "90"> <br> another Joint Product from <a href = "http: //www.ncws .com / tippycow "> Tipped Cow Development </a> and <a href="http://dstoflet.calweb.com"> Adrenalin Labs </a> <br> <br> </ div> <table width = "100%" cellspacing = "0" cellpadding = "2"> <tr> <td align = "left" width = "25%" Valign = "TOP" class = "bold"> <form action = "default.asp > <table width = "100" border = "1" bordercolor = # ccccff> <tr> <TD> <table border = 0 cellspacing = 0 cellpadding = 5 bgcolor = # 4f4f4f> <tr> <td colspan = 3 BGColor = # 000000 align = center class = "bold2"> SELECT A Poll </ td> </ tr> <tr> <td colspan = 3 bgcolor = # 000000 align = center> <select name = "ID" onchange = "Gatherform (this.form) "Class =" INPUT "> <% set conn = server.createObject (" adoDb.connection ") Conn.open Application (" asppolldsn ") SQL =" SELECT * from Poll "set = conn.execute (SQL) Do While Not Rs.eof%> <option value = "<% = rs (" ID ")%>> <% = rs (" pollname ")%></p> <p><% rs.movenextloop%></p> <p></ select> </ tr></p> <p><TR> <TD COLSPAN = 3 Align = Right Bgcolor = # ffffff Class = "Bold"> Vote in Poll: <input type = "radio" name = "mode" value = "vote" Checked> <br> View Results: <Input Type = "Radio" name = "mode" value = "view"> </ td> </ tr> <tr> <td color = # 000000 align = center> <input type = Button "value =" Go "onclick =" Gatherform (this.form) "class =" inline "> </ td> </ tr></p> <p></ table> </ td> </ tr> </ table> </ form> <br> <div align = "left" class = "bold"> <a href="create_poll1.asp"> Create Your Own Poll </A> <br> <a href=javascript:History.back () back </a> </ div> </ td></p> <p><TD align = "center" width = "75%" Valign = "TOP"> <table width = "100" border = 1 cellspacing = 2 cellpadding = 0 bordercolor = # ccccff> <tr> <TD> <form method = "post" action = "collect.asp"> <input type = "hidden" name = "id" value = "<% = id%>"></p> <p><% Set conn = server.createObject ("adodb.connection") conn.open application ("asppolldsn") SQL = "SELECT * from stick where id =" & idset = conn.execute (SQL) if xi = False Then%></p> <p><table border = 0 cellspacing = 0 cellpadding = 10 bgcolor = # 4f4f4f> <tr> <td colspan = 3 bgcolor = # 2f2f4f align = center> <font face = "verdana" color = # f5FCDC> Poll: <% = rs ("pollname")%> </ td> -> </ tr> <tr> <td colspan = 3 bgcolor = # 000000 align = left class = "bold2"> <% = rs ("PollQuestion ")%> </ tr> <% for i = 1 to 5choice = = = = 1 to 5choice = RS (" Choice "& i) if Choice <>" "" "" <Tr> <! - <td width = 50 COLSPAN = 1 BGColor = # 4f4f4f> </ td> -> <td colspan = 2 bgcolor = # ffffFFFFFFFFFFFFFFFFFFFFFFFFFFFFC Class = "bold" align = "left"> <% = cho% = # ffffff align = " LEFT "> <input type =" radio "name =" choice "value =" <% = i%> "> </ td> </ tr> <% end ifnext%> </ tr> <% IF r (" GetName ") =" 1 "THEN> <TR> <TD colspan = 1 align = Right BGColor = # ffffff class =" bold "> Your name: </ td> <td color = 2 align = right bgcolor = # ffffffff > <input type = "text" name = "name"> </ td> <TR> <% end if%> <tr> <td color = 3 align = right bgcolor = # 000000 align = center> <input type = "Submit" value = "submit vote" class = "inline"> </ td> </ tr> </ table></p> <p><% Elseresponse.write "Invalid Poll ID Request!" END IF%> </ TD> </ TR> </ form> </ table></p> <p></ td> </ tr> </ table> </ body> </ html></p> <p>5, file global.asa <SCRIPT LANGUAGE = "VBScript" RUNAT = "SERVER"> Sub Application_OnStartApplication ( "ASP_Poll") = "ASP_Poll" cnString = "DRIVER = {Microsoft Access Driver (* .mdb)};" cnString = cnString & "Dbq =" & server.mappath ("events.mdb") Application ("asppolldsn") = cnstringend Sub </ script></p> <p>6. File pool.inc <% dbpath = server.mappath ("/ poll / events.mdb") ID = 28if request.cookies ("polLid") = cstr (id) ThenshowdisplayelseeshowvoteEnd IF</p> <p>Function ConvertTopercent (Total, SZ) IF SZ = 0 ThenConvertTopercent = "0%" ElseconvertTopercent = Formatpercent (SZ / Total, 2) End IFEND Function</p> <p>Sub showvote</p> <p>%></p> <p><div align = Right> <table width = 125 border = 1 cellspacing = 0 cellpadding = 0> <tr> <td> <form method = "post" action = "/ polL / collect.asp"> <input type = " Hidden "name =" value = "<% = id%>> <input type =" hidden "name =" RETURN_PAGE "value =" <% = Request.serverVariables ("Path_INFO")%>> <% Set conn = Server.CreateObject ( "ADODB.Connection") dsnpath = "DRIVER = {MICROSOFT ACCESS DRIVER (* .mdb)};" dsnpath = dsnpath & "DBQ =" & DBPathconn.open dsnpathsql = "select * from Poll where ID = "& idse = conn.execute (sql) if = = false the%></p> <p><table width = 125 border = 0 cellspacing = 0 cellpadding = 2 bgcolor = # 4f4f4f> <tr> <td colspan = 3 bgcolor = # 2f2f4f align = center> <% = rs ("pollquestion")%> </ td> </ TR> <% for i = 1 to 5choice = = = = r ("Choice" & i) if Choice <> "" ""> <TR> <TD colspan = 2 bgcolor = # 000000 valign = top width = 80%> <% = choice%> </ td> <td valign = top colspan = 1 width = 20% bgcolor = # 000000> <input type = "radio" name = "choice" value = "<% = i%>">> </ td> </ tr> <TR> <TD colspan = 3 align = center bgcolor = # 2f2f4f align = Right> <input type = "submit" value = "submit" class = NAV> < / TD> </ tr> </ table> <% end if%></p> <p></ td> </ tr> </ form> </ table></p> <p></ center></p> <p><%</p> <p>End Sub</p> <p>Sub showdisplay</p> <p>Set conn = server.createObject ("adodb.connection") SQL = "Select * from poll where id =" & cint (id) DSNPATH = "driver = {Microsoft Access Driver (* .mdb)};" DSNPATH = DSNPATH & "Dbq =" & dbpathconn.open dsnpathset = conn.execute (SQL) if = = false thendim choices (6) Dim Responses (6) for i = 1 to 5choice = RS ("Choice" & i) Choices I) = choiceIf choice <> "" ThenSet conn2 = Server.CreateObject ( "ADODB.Connection") sql = "select COUNT (PollAnswer) from PollResults where PollID =" & Cint (id) & "AND PollAnswer =" & Idsnpath = "Driver = {Microsoft Access Driver (* .mdb)};" DSNPATH = DSNPATH & "DBQ =" & dbpathconn2.open DSNPATHSET RS2 = conn.execute (SQL) IF = re = false tellSponse (i) = r = r2 (0 ) End ifrs2.closeconn2.closend ifnext%> <div align = "right"> <table border = 1 cellspacing = 0 cellpadding = 2> <tr> <td> <Table width = 125 border = 0 cellspacing = 0> <tr > <td colspan = 2 bgcolor = # 2f2f4f align = center class = orgbold> ASP Poll </ td> </ tr> <tr> <td color = # ccccff class = black> Q: <% = RS ("pollquestion")% > </ td> </ tr></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-22414.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="22414" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.053</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'lPdIfvUdSIGzLfemu0FkTL47CEHQN2XMHjMlN6gEchqCgV0L12d8NwVkAz8BzWlrQ7bL5vXckc_2BvqX2_2BsIOAxQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>