Avatar billede justdoit Nybegynder
14. marts 2002 - 14:17 Der er 7 kommentarer og
2 løsninger

Vote virker ikke

Jeg har fundet et script som jeg gerne vil bruge til min hjemmeside, men når jeg har downloadet filerne og prøver at gå ind i fx vb_admin.asp så får jeg en fejl jeg ikke kan finde ud af - er der nogle der kan hjælpe??

http://www.smashco.com/dev.asp



Justdoit:)
Avatar billede coltau Juniormester
14. marts 2002 - 14:19 #1
Hvilken fejl. ?
Avatar billede migb Nybegynder
14. marts 2002 - 14:20 #2
Det ville være lettere at svare på, hvis du kunne beskrive scriptet og fejlmeddelelsen.
Prøv evt. at kopiere scriptet direkte som tekst i stedet for som en fil.
Avatar billede justdoit Nybegynder
14. marts 2002 - 14:33 #3
OK - det fylder lidt meget da der er 3 filer, men hva pyt:)

Det er 3 asp filer, og dertil hører der jo også en database, men den kan jeg ikke lige sende!

Min fejlmelding er:

Microsoft JET Database Engine fejl '80004005'

"C:\myfile\html\database\vb2k.mdb" er ikke en gyldig sti. Kontroller, at stinavnet er stavet korrekt, og at du er tilsluttet den server, hvor filen findes.

/dvdit/dvdit-filer/vote/vb.asp, linje 188


Her er vb_admin.asp

<%response.buffer = true%>
<%Response.Expires = -10000%>
<!-- #include file="vb.asp"-->

<table border="0" width="<%=VB_ADMINWIDTH%>">
<tr><td align="left">

<%
if request("func") <> "" then
    strFunc = request("func")
    else
    strFunc = request.form("func")
end if


Select Case strFunc
    Case "login"
        call login
    Case "control"
        call control
    Case "edit"
        call edit
    Case "user"
        call user
    Case else
        session.abandon
        call login
end select
%>


<%
Sub Control
    call checksession
    if request.form("setactive") = "yes" then
        ' Set the checked item to active and
        ' remove active flag from old active entry
        strSQL = "SELECT * FROM question"
        set rst = Server.CreateObject("ADODB.Recordset")
        rst.open strSQL, Connect, 1, 3, 1
        intID = cInt(request.form("id"))
        do while NOT rst.EOF
        if rst("id") = IntID then
            rst("active") = true
        else
            rst("active") = false
        end if
        rst.MoveNext
        loop
        rst.close
    end if
   
    if request("action") = "delete" then
        ' Open question table and delete appropriate entry
        strSQL = "SELECT * FROM question WHERE id = " & request("id")
        set rst = Server.CreateObject("ADODB.Recordset")
        rst.open strSQL, Connect, 1, 3, 1
        if rst.RecordCount = 0 then
            rst.close
            else
        rst.delete
        rst.close
       
        ' Open answer table and delete corresponding answers
        strSQL = "SELECT * FROM answer WHERE parent = " & request("id")
        rst.open strSQL, Connect, 1, 3, 1
        do while NOT rst.EOF
            rst.delete
            rst.moveNext
        loop
        rst.close
       
        'respond with message that deletion was successful
        %>
       
      <table border="0" cellpadding = "0" bgcolor="#FFFFFF">
        <tr>
          <td bgcolor="#CCCCCC"><font face="verdana" size="4" color="white"><font color="#000000">Poll
            deleted.</font></font></td>
        </tr></table><br />
        <%
        end if
    end if
   
    if request("action") = "inactive" then
        strSQL = "SELECT * FROM question WHERE active = true"
        set rst = Server.CreateObject("ADODB.Recordset")
        rst.open strSQL, Connect, 1, 3, 1
        if rst.RecordCount = 0 then
        else
            rst("active") = false
            rst.update
        end if
        rst.close
    end if
   
    %>
    <font face="verdana" size="5" color="maroon">Voting Booth Control Panel</font>
    <%Call UserMenu%>
   
    <b><font face="verdana" size="2">The following polls are in your database.<br />
    Click the poll name to edit it.</font></b>
   
    <form method="post" action="vb_admin.asp?func=control">
   
    <table border="<%=intTableBorder%>" cellpadding="<%=VB_CELLPADDING%>" cellspacing="<%=VB_CELLSPACING%>">
    <tr>
        <td><font face="verdana" size="1"><b>Active</b></font></td>
        <td><font face="verdana" size="1"><b>Question (ID)</b></font></td>
        <td><font face="verdana" size="1"><b>Total Votes</b></font></td>
        <td><font face="verdana" size="1"><b>Delete</b></font></td>
    </tr>
    <%
    set rst = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT * FROM question ORDER BY active"
    rst.open strSQL, Connect, 3, 1, 1
    intRecCount = rst.RecordCount
    bgcolor = VB_COLOR2
    do while NOT rst.EOF
   
    %>
    <tr>
    <td align="center" bgcolor="<%=bgcolor%>"><input type="radio" name="id"
        <%
        if rst("active") = true then
        %>
        checked
        <%
    end if
    %>
    value="<%=rst("id")%>"></td>
    <td bgcolor="<%=bgcolor%>"><a href="vb_admin.asp?func=edit&action=modify&id=<%=rst("id")%>"><font face="verdana" size="1"><%=rst("question")%> (ID=<%=rst("id")%>)</font></a></td>
    <td bgcolor="<%=bgcolor%>"><font face="verdana" size="1"><b><%=rst("total")%></b></font></td>
   
    <td bgcolor="<%=bgcolor%>" align="center"><a href="vb_admin.asp?func=control&action=delete&id=<%=rst("id")%>"><img src="images/x.gif" border="0" /></a></td>
    </tr>
    <%
   
    If bgcolor=VB_COLOR1 Then
        bgcolor = VB_COLOR2
        else
        bgcolor = VB_COLOR1
    end if   
   
    rst.MoveNext
    loop
    rst.close
    %>
    </table>
    <br />
    <input type="submit" name="submit" value="Set Active">
    <input type="hidden" name="setactive" value="yes">
    </form>
    <a href="vb_admin.asp?func=control&action=inactive"><font face="verdana" size="2">Make all polls inactive</font></a>
    </td></tr>
    </table>
    <%
end sub 'Control

sub login
    if request.form("login") = "Login" then
        strSQL = "SELECT * FROM users WHERE user = '" & request.form("user") & "' AND pass = '" & request.form("pass") & "'"
        'response.write strSQL & "<P>"
        set rst = Server.CreateObject("ADODB.Recordset")
        rst.open strSQL, Connect, 3,1,1
        if rst.RecordCount = 0 then
            %>
           
<table border="0" cellpadding = "0" bgcolor="#CCCCCC">
  <tr>
               
    <td><font face="verdana" size="4" color="white"> <font color="#000000">Invalid
      user or password. Please try again.</font></font></td>
            </tr></table><br />
            <%
            rst.close
            Connect.close
        else
            session("user") = rst("id")
            rst.close
            Connect.close
            response.redirect "vb_admin.asp?func=control"
        end if
    end if
    %>
   
    <font face="verdana" size="5" color="maroon">Voting Booth Administrative Login</font>
    <form action="vb_admin.asp" method="post">
    <table border="0" cellpadding="8" cellspacing="0">
    <tr bgcolor="<%=VB_COLOR2%>">
        <td align="right"><font face="verdana" size="2"><b>User Name:</b></font></td>
        <td align="left"><input type="text" name="user" size="20"></td>
    </tr>
    <tr bgcolor="<%=VB_COLOR2%>">
        <td align="right"><font face="verdana" size="2"><b>Password:</b></font></td>
        <td align="left"><input type="password" name="pass" size="20"></td>
    </tr>
    <tr bgcolor="<%=VB_COLOR1%>">
        <td colspan="2" align="center"><input type="submit" value="Login" name="login"></td>
    </tr>
    </table>
    <input type="hidden" name="func" value="login"></form>
    <%
end sub 'login


sub edit
    call checksession
   
    '******************
    '****************
    if request.form("doit") = "yes" then
        if request.form("update") = "update" then
            booUpdateFlag = true
            intParent = request.form("id")
        end if
       
        if request.form("cancel") = "Cancel" then
            ' Cancel button hit. Redirect user back to admin page.
            response.redirect "vb_admin.asp?func=control"
            response.flush
            response.end
        end if
       
        if len(request.form("question")) < 1 or len (request.form("question")) > 225 then
            %>
           
<table border="0" cellpadding = "0" bgcolor="red">
  <tr><td><font face="verdana" size="4" color="white">
            Mellem 1 og 255 tegn.</font></td>
            </tr></table><br />
            <%
            intErrorFlag = 1
        end if
           
        dim arrayQuestion()
        dim arrayVote()
            for intStep = 1 to 8
            if request.form("answer_" & intStep) <> "" then
                if len(request.form("answer_" & intStep)) > 225 then
                    %>
                   
<table border="0" cellpadding = "0" bgcolor="red">
  <tr><td><font face="verdana" size="4" color="white">
                    Please limit answers to 225 characters.</font></td>
                    </tr></table><br />
                    <%
                    intErrorFlag = 1
                end if
                arrayCount = arrayCount+1
                redim preserve arrayQuestion(arrayCount)
                redim preserve arrayVote(arrayCount)
                arrayQuestion(arrayCount) = request.form("answer_" & intStep)
                arrayVote(arrayCount) = request.form("vote_" & intStep)
                if NOT isNumeric(arrayVote(arrayCount)) then
                    arrayVote(arrayCount) = "0"
                end if
            end if
            next
       
        ' Lets get the total number of votes
        dim intVoteTotal
        for intVoteTotalCount = 1 to arrayCount
            intVoteTotal = intVoteTotal + CLng(arrayVote(intVoteTotalCount))
        next
       
        if arrayCount = 0 then
            %>
           
<table border="0" cellpadding = "0" bgcolor="red">
  <tr><td><font face="verdana" size="4" color="white">
            Please enter at least one answer.</font></td>
            </tr></table><br />
            <%
            intErrorFlag = 1
        end if
       
        if intErrorFlag <> 1 then
            ' Everything is ok. Lets proceed:
            ' Make connection and define recordset
            set rst = Server.CreateObject("ADODB.Recordset")
           
            ' Write question
            if booUpdateFlag then
                strSQL = "SELECT * FROM question WHERE id = " & intParent
                else
                strSQL = "SELECT * FROM question"
            end if
            rst.open strSQL, Connect, 1, 3, 1
            if booUpdateFlag then
                rst.update
                else
                rst.addnew
            end if
            rst("question") = request.form("question")
            rst("total") = intVoteTotal
            rst.update
            intParent = rst("id")
            rst.close
           
            ' Write answers
            if booUpdateFlag then
                strSQL = "SELECT * FROM answer WHERE parent = " & intParent
                rst.open strSQL, Connect, 1, 3, 1
                for intCount = 1 to rst.RecordCount
                    rst.delete
                    rst.MoveNext
                next
                rst.close
                strSQL = "SELECT * FROM answer"
                else
                strSQL = "SELECT * FROM answer"
            end if
            rst.open strSQL, Connect, 1, 3, 1
            for intCount = 1 to ArrayCount
                rst.addnew
                rst("answer") = arrayQuestion(intCount)
                rst("vote") = arrayVote(intCount)
                rst("parent") = intParent
                rst.update
            next
            rst.close
           
            response.redirect "vb_admin.asp?func=control"
            response.flush
            response.end
        end if
    end if
    '*******************
    '******************
   
    if request("action") = "modify" or request.form("action") = "modify" then
        booModify = true
        intModId = request("id")
        set rst = Server.CreateObject("ADODB.Recordset")
       
        ' Get question
        strSQL = "SELECT * FROM question WHERE id = " & intModID
        rst.open strSQL, Connect, 3, 1, 1
        strQuestion = rst("question")
        intID = rst("id")
        rst.close
       
        ' Get answers and votes
        dim ArrayModAnswer()
        dim ArrayModVote()
        strSQL = "SELECT * FROM answer WHERE parent = " & intModID & " ORDER BY id;"
       
        rst.open strSQL, Connect, 3, 1, 1
        intModAnswerCount = rst.RecordCount
        redim ArrayModAnswer(intModAnswerCount)
        redim ArrayModVote(intModAnswerCount)
        for intCount = 1 to intModAnswerCount
            arrayModAnswer(intCount) = rst("answer")
            arrayModVote(intCount) = rst("vote")
            rst.MoveNext
        next
        rst.close
    end if
   
    if NOT booModify then
        response.write "<font face=verdana size=5 color=maroon>Create new poll</font>"
        else
        response.write "<font face=verdana size=5 color=maroon>Edit existing poll</font>"
    end if
    %>
    <%Call UserMenu%>
    <b><font face="verdana" size="2">Enter the question this poll will ask:</b></font><br />
    <form method = "post" action = "vb_admin.asp">
    <input type = "text" name = "question" size="50"
        <%if booModify then%>value="<%=strQuestion%>"<%end if%>><br />
        <hr />
    <b><font face="verdana" size="2">Enter the answers to your question below.<br />
    You must enter at least one answer.</font></b>
    <br /><br />
   
    <table border="<%=intTableBorder%>" cellpadding="<%=VB_CELLPADDING%>" cellspacing="<%=VB_CELLSPACING%>">
    <tr>
        <td><font face="verdana" size="1"><b>ID</b></font></td>
        <td><font face="verdana" size="1"><b>Answer</b></font></td>
        <td><font face="verdana" size="1"><b>Votes</b></font></td>
    </tr>
    <%
    bgcolor = VB_COLOR1
    for intCount = 1 to 8
    %>
    <tr>
        <td align="left" bgcolor="<%=bgcolor%>"><%=intCount%>.</td>
        <td bgcolor="<%=bgcolor%>"><input size="30" type="text" name="answer_<%=intCount%>"
            <%if (booModify AND intCount =< intModAnswerCount) then%>
            value="<%=arrayModAnswer(intCount)%>"<%end if%>></td>
        <td bgcolor="<%=bgcolor%>"><input size="7" type="text" name="vote_<%=intCount%>"
            <%if (booModify AND intCount =< intModAnswerCount) then%>
            value="<%=arrayModVote(intCount)%>"<%else%>
            value="0"><%end if%></td>
    </tr>
    <%
    If bgcolor=VB_COLOR1 Then
        bgcolor = VB_COLOR2
        else
        bgcolor = VB_COLOR1
    end if   
    next
    %>
    </table><br />
   
    <input type="submit" name = "submit" value = "Save">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="submit" name = "cancel" value = "Cancel">
    <%
    if booModify then
        %>
        <input type="hidden" name = "update" value = "update">
        <input type="hidden" name = "id" value = "<%=intID%>">
        <input type="hidden" name = "action" value="modify">
        <%
    end if
    %>
    <input type="hidden" name="doit" value="yes">
   
    <!-- <input type="hidden" name="func" value="writepoll"> -->
    <input type="hidden" name="func" value="edit">
    </form>
    </td></tr>
    </table>
    <%
end sub 'edit

sub user
    call CheckSession
        set rst = Server.CreateObject("ADODB.Recordset")
        if request("action") = "delete" then
            if cInt(request("id")) <> cInt(session("user")) then
                ' ok to delete selected user. It is not the same one logged in under
                strSQL = "SELECT * FROM users WHERE id = " & request("id")
                rst.open strSQL, Connect, 1, 3, 1
                if rst.RecordCount = 0 then
                    rst.close
                    else
                rst.delete
                rst.close
                end if
           
                %>
               
<table border="0" cellpadding = "0" bgcolor="red">
  <tr>
                <td><font face="verdana" size="4" color="white">
                User deleted.</font></td>
                </tr></table><br />
                <%
                else
                ' User is trying to delete the user name that was logged in under.
                ' Send a message.
                %>
               
<table border="0" cellpadding = "0" bgcolor="red">
  <tr>
                <td><font face="verdana" size="4" color="white">
                It is not possible to delete the current user.</font></td>
                </tr></table><br />
                <%
            end if
        end if
       
        if request.form("new") = "yes" then
            ' Create new user button clicked.
            if (request.form("user") = "" or request.form("pass") = "") then
                ' Either user or pass was left empty.
                ' Send an error message.
                %>
               
<table border="0" cellpadding = "0" bgcolor="red">
  <tr>
                <td><font face="verdana" size="4" color="white">
                Please enter a user name AND password.</font></td>
                </tr></table><br />
                <%
                elseif (len(request.form("user")) > 8 or len(request.form("pass")) > 8) then
                ' Given user name or password are longer than 8 chars
                ' Send s message
                %>
               
<table border="0" cellpadding = "0" bgcolor="red">
  <tr>
                <td><font face="verdana" size="4" color="white">
                Please limit user name and password to eight characters or less.</font></td>
                </tr></table><br />
                <%
                else
                ' Otherwise, everything looks good.
                ' Lets check for duplicate user name
                strSQL = "SELECT * FROM users WHERE user = '" & request.form("user") & "'"
                rst.open strSQL, Connect, 1, 3, 1
               
                if rst.RecordCount <> 0 then
                    ' The user name entered already exists in data base
                    ' Send a message
                    %>
                   
<table border="0" cellpadding = "0" bgcolor="red">
  <tr>
                    <td><font face="verdana" size="4" color="white">
                    User name already exists. Choose another.</font></td>
                    </tr></table><br />
                    <%
                    rst.close
                    else
                   
                    ' User name is unique. Let's write user.
                    rst.addnew
                    rst("user") = request.form("user")
                    rst("pass") = request.form("pass")
                    rst.update
                    rst.close
                    %>
                   
<table border="0" cellpadding = "0" bgcolor="red">
  <tr>
                    <td><font face="verdana" size="4" color="white">
                    User created.</font></td>
                    </tr></table><br />
                    <%
                end if
            end if
        end if
    %>
   
   
    <font face="verdana" size="5" color="maroon">Edit Users</font>
    <%Call UserMenu%>
    <table border="<%=intTableBorder%>" cellpadding="<%=VB_CELLPADDING%>" cellspacing="<%=VB_CELLSPACING%>">
   
    <tr>
        <td><font face="verdana" size="1"><b>User ID</b></font></td>
        <td><font face="verdana" size="1"><b>User Name</b></font></td>
        <td><font face="verdana" size="1"><b>Delete</b></font></td>
    </tr>
   
    <%
    strSQL = "SELECT * FROM users"
    rst.open strSQL, Connect, 3, 1, 1
    bgcolor = VB_COLOR1
    do while NOT rst.EOF
        %>
        <tr bgcolor="<%=bgcolor%>">
        <td align="center"><%=rst("id")%></td>
        <td align="left"><%=rst("user")%></td>
        <td align="center">
            <%if session("user") <> rst("id") then
                %>
                <a href="vb_admin.asp?func=user&action=delete&id=<%=rst("id")%>"><img src="images/x.gif" border="0" /></a>
                <%
                else
                response.write "&nbsp;"
            end if%>
        </td>
        </tr>
        <%
       
    If bgcolor=VB_COLOR1 Then
        bgcolor = VB_COLOR2
        else
        bgcolor = VB_COLOR1
    end if   
   
    rst.MoveNext
    loop
    rst.close
    %>
    </table>
    <hr />
   
    <form action="vb_admin.asp" method="post">
    <table border="<%=intTableBorder%>" cellpadding="<%=VB_CELLPADDING%>" cellspacing="<%=VB_CELLSPACING%>">
    <tr bgcolor=<%=VB_COLOR2%>>
        <td align="left"><font face="verdana" size="1"><b>New user</b></font></td>
        <td align="left"><input type="text" name="user" size="15"></td>
    </tr>
    <tr bgcolor=<%=VB_COLOR2%>>
        <td align="left"><font face="verdana" size="1"><b>Password</b></font></td>
        <td align="left"><input type="password" name="pass" size="15"></td>
    </tr>
    <tr bgcolor=<%=VB_COLOR1%>>
        <td align="center" colspan="2">
        <font face=verdana size=1><b><input type="submit" name="newuser" value="Create New User"></b></font>
        </td>
    </tr>
    </table>
    <input type="hidden" name="func" value="user">
    <input type="hidden" name="new" value="yes">
    </form>
   
    </td></tr>
    </table>
<%end sub 'user%>



Her er vb.asp

<%Response.Expires = -10000%>
<!-- #include file="vb_vars.asp"-->
<%
' The user has cast a vote
' Let's deal with that here
if request.form("voted") = "true" then
    'user sent a malformed request. Let's dump out.
    if request.form("id") = "" then response.redirect VB_HOSTFILE
   
    if ((VB_RESTRICT) and (request.cookies("vb") = "")) or NOT VB_RESTRICT then
            'Either VB_RESTRICT is set to true and user DOES NOT have cookie or
            'VB_RESTRICT is set to false. Thus, it's OK to vote.
           
            'If VB_RESTRICT is true, write the cookie
            if VB_RESTRICT then
                'Cookie name is 'vb', expiry time of cookie is NOW + VB_TIMETORESTRICT
                Response.Cookies("vb") = "vb"
                Response.Cookies("vb").Expires = DateAdd("h", VB_TIMETORESTRICT, Now)
            end if
                       
            ' ==== BEGIN write new vote ==============================
            ' New stuff here: added feb 11, 2002
            pollid = request.form("pollid")
            answerid = request.form("id")
            strSQL = "SELECT question.id, question.question, question.total, answer.vote, answer.id "
            strSQL = strSQL & "FROM answer INNER JOIN question ON answer.parent = question.id "
            strSQL = strSQL & "WHERE (((question.id)=" & pollid & ") AND ((answer.id)=" & answerid & "));"
           
            'response.write STRSQL
            'response.end
           
            'Define and open the recordset in write mode (1,3,1)
            set rst = Server.CreateObject("ADODB.Recordset")
            rst.open strSQL, Connect, 1, 3, 1
           
            ' get values from recordset...
            intQuestionId = rst("question.id")
            strQuestion = rst("question")
            intTotal = rst("total")
            intAnsTotal = rst("vote")
           
            intTotal = intTotal + 1
            intAnsTotal = intAnsTotal + 1
           
            rst("total") = intTotal
            rst("vote") = intAnsTotal
            rst.update
            rst.close
            connect.close
            ' End new stuff
           
            ' ==== END write new vote ====================================
        else
            'not ok to vote.
            'Don't do anything
    end if   
   
    'Whether or not a vote was cast, redirect to same page but display results.
    'The poll to display is in the request.form variable 'pollid'.
    intPollId = request.form("pollid")
    response.redirect VB_HOSTFILE & "?id=" & intPollID & "&results=true"
end if
%>
<%
sub VotingBooth
'To debug cookies, un-rem (yes, that's now a verb!) the next line to expire cookie each time
'Response.Cookies("vb").Expires = Now() - 1
    if (request.cookies("vb") <> "") and VB_RESTRICT then
        call DisplayResults
    else
        Select case request("results")
            Case "true"
                Call DisplayResults
            Case else
                Call DisplayVote
        end select
    end if
end sub
%>

<%
sub DisplayVote
    strSQL = "SELECT question.question, answer.answer, answer.id, question.id "
    strSQL = strSQL & "FROM answer INNER JOIN question ON answer.parent = question.id "
    strSQL = strSQL & "WHERE (((question.active)=True));"
   
    set rst = Server.CreateObject("ADODB.Recordset")
    rst.open strSQL, Connect, 3,1,1
   
    if rst.RecordCount <> 0 then
        strQuestion = rst("question")
        intPollID = rst("question.id")
        with response
            .write "<table border=0 cellpadding=" & VB_TABLEPADDING & " align=" & VB_TABLEALIGN & "><tr><td align=center>"
            .write "<form action=" & VB_URL & "/vb.asp method=post>"
            .write "<table border=0 cellpadding=2 cellspacing=2 width=" & VB_TABLEWIDTH & " align=" & VB_TABLEALIGN & " hspace=10 vspace=10 bgcolor=" & VB_COLOR2 & ">"
            .write "<tr><td colspan=2 align=center bgcolor=" & VB_COLOR1 & "><font face=verdana size=1><b>" & strQuestion & "</b></td></tr>"
        end with
   
        do while not rst.EOF
            with Response
                .write "<tr><td align=center>"
                .write "<input type=radio name=id value = " & rst("answer.id") & "></td>"
                .write "<td align=left><font face=arial size=1>" & rst("answer") & "</font></td></tr>"
            end with
            rst.MoveNext
        loop
        rst.close
        with response
            .write "<tr><td align=center colspan=2><input type=submit name=vote value=vote!></td></tr>"
            .write "<tr><td align=center colspan=2><font face=arial size=1>"
            .write "<a href=" & VB_HOSTFILE & "?results=true>View results without voting</a></font>"
            .write "</table><br>"
            .write "<input type=hidden name=voted value=true>"
            .write "<input type=hidden name=pollid value=" & intPollId & ">"
            .write "</form></td></tr></table>"
        end with
    else
        'response.write "<h2>No current poll</h2>"
    end if
    Connect.close
end sub
%>

<%
Sub DisplayResults
    strSQL = "SELECT question.question, answer.answer, answer.vote, question.total "
    strSQL = strSQL & "FROM answer INNER JOIN question ON answer.parent = question.id "
    strSQL = strSQL & "WHERE (((question.active)=True));"
   
    set rst = Server.CreateObject("ADODB.Recordset")
    rst.open strSQL, Connect
    strQuestion = rst("question")
    intTotal = rst("total")
   
    response.write "<table border=0 cellpadding=" & VB_TABLEPADDING & " align=" & VB_TABLEALIGN & ">"
    response.write "<tr><td align=center>"
    response.write "<table border=0 cellpadding=2 cellspacing=2 width=" & VB_TABLEWIDTH & " align=" & VB_TABLEALIGN & " hspace=10 vspace=10 bgcolor=" & VB_COLOR2 & ">"
    response.write "<tr><td align=center bgcolor=" & VB_COLOR1 & "><font face=verdana size=1><b>Poll Results:<br />" & strQuestion & "</b></td></tr>"
   
    intHighest = 0
    do while not rst.EOF
        if rst("vote") > intHighest then
            intHighest = rst("vote")
        end if
        rst.moveNext
    loop
    rst.moveFirst
   
    'Stepping throught the recordset.
    'Each time, we determine the length of the bar, based on code chunk just before
    do while not rst.EOF
    if intHighest > VB_BARLENMAX then
        intDivBy = intHighest/VB_BARLENMAX
        intWidth = round((rst("vote")/intDivBy),0)
    else
        intMultBy = VB_BARLENMAX/(IntHighest+.0001)
        'response.write intMarLenMax
        'response.end
        intWidth = round((rst("vote")*intMultBy),0)
    end if
       
   
    response.write "<tr><td align=left><font face=arial size=1>" & rst("answer") & "<br>"
    if rst("vote") <> 0 then
        response.write "<img src=" & VB_URL & "/images/bar_" & VB_BARCOLOR & ".jpg height=8 width=" & intWidth & ">"
        response.write "&nbsp;" & rst("vote") & " (" & round(((rst("vote")/intTotal)*100),VB_DECPLACES) & "%)<br>"
        else
            response.write rst("vote") & " (0%)<br>"
            'response.write "no votes<br />"
    end if
    response.write "<img src=" & VB_URL & "/images/bar_" & VB_BARCOLOR & ".jpg height=1 width=" & VB_TABLEWIDTH & ">"
    response.write "</td></tr>"
   
    rst.MoveNext
    loop
    response.write "</table></td></tr></table>"
    rst.close
end sub
%>

<%
'This function makes the connection to your database.
'VB_STRCON is defined in the user variable include file.
function Connect()
    set con=Server.CreateObject("ADODB.connection")
    con.ConnectionString = VB_STRCON
    con.open
    set Connect = con
end function
%>

<%
' This sub verifies that a current session variable has not been emptied out.
' If it has, the session has ended due to a timeout or malformed URLs.
' The session state is checked at the start of each script in the 'admin' directory.
' You can modify the code here to redirect, or anything else you'd want.
sub CheckSession
    if session("user") = "" then
        %>
        <center>
        <font face="verdana" size="4" color="maroon">You have reached this page in error,<br />
        or your session has timed out.<br /><br />
        Please <a href="vb_admin.asp">login</a> again.</font>
        </center><%
        response.end
    end if
end sub
%>


<%
sub UserMenu()
%>
    <hr />
    <font face="verdana" size="1"><b>
    <a href="vb_admin.asp?func=control">Control panel</a> |
    <a href="vb_admin.asp?func=edit">Create new poll</a> |
    <a href="vb_admin.asp?func=user">Edit users</a> |
    <a href="vb_admin.asp">Log out</a>
    </b></font>
    <hr />
<%
end sub
%>


Her er vb_vars.asp

<%
'This file contains all variables pertaining to general operation and customization.
'Each variable is described below.
'Note that if you modify a variable name, or define any variable with
'an unsuspected subtype, the application may error or act erratic.

'Connection string
'This value defines the connection string when connecting to the database.
VB_STRCON = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:myfile\html\database\vb2k.mdb"

'Absolute URL to host file
VB_HOSTFILE = "http://www.smashco.com/votebthcfg.asp"

'Application directory as absolute URL
VB_URL = "http://www.smashco.com/plugins"

'Bar graph maximum bar length:
'The responses to each poll are displayed both numerically and with bar graphs.
'In order to keep these bar graphs a manageable size, set this variable
'to the maximum length, in pixels, that the largest bar in a graph will be.
'It is recommended that you don't mess with the VB_TABLEWIDTH value.
VB_BARLENMAX = 60
VB_TABLEWIDTH = VB_BARLENMAX + 60

'Display colors
'These variables set the colors of the voting card and poll results table.
'VB_COLOR1 sets the color of the background of the header of the table.
'VB_COLOR2 sets the color of the background of the body of the table.
'These values can be hex color values (#66cccc) or HTML color literals (maroon).
VB_COLOR1 = "#66CCCC"
VB_COLOR2 = "#CCCC99"
VB_ADMINWIDTH = 500
VB_TABLEBORDER = 1
VB_CELLSPACING = 0
VB_CELLPADDING = 3

'Table Alignment
'This variable sets the alignment of the voting card or poll results table.
VB_TABLEALIGN = "right"
VB_TABLEPADDING = 20

'Bar graph color:
'Set this to the color that you would like the bars in all graphs to display.
'Available values are: "blue", "green", "maroon", "navy", "purple".
'These options are based on image files supplied with the source
VB_BARCOLOR = "maroon"

'Percent decimal places
'Set this variable to the number of decimal places to display in the
'poll results table.
VB_DECPLACES = 0

'IP restriction:
'Voting booth can restrict voters from voting multiple times in any given period.
'To use this feature, set VB_RESTRICT to true
VB_RESTRICT = false

'Hours to restrict voting:
'Set this variable to the period of time, IN HOURS, that you want to restrict polling from an IP address.
'This value is unused if the IP restriction setting is false.
VB_TIMETORESTRICT = 24
%>
Avatar billede coltau Juniormester
14. marts 2002 - 22:13 #4
Jeg downloadede projektet fra hjemmesiden.

Jeg har derefter flyttet databasen vb2k.mdb - så den ligger i samme mappe som ASP-koderne og derefter ændret linie 9 i vb_vars.asp til:

VB_STRCON = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("vb2k.mdb")

Så køre det. :-)
Avatar billede justdoit Nybegynder
15. marts 2002 - 07:56 #5
Du er en guttermand:)

Jeg skal lige høre hvad det er for et script som jeg skal sætte ind på selve hjemmesiden for at afstemningen kommer derud!

Er det det her??

<%Response.Expires = -100000
Response.Buffer = true%>
<!-- #include virtual="plugins/vb.asp"-->
<%call VotingBooth%>
Avatar billede coltau Juniormester
15. marts 2002 - 09:49 #6
det kommer an på hvordan det skal implementeres på din hjemmeside - men ovenstående kan vel bruges.
Avatar billede justdoit Nybegynder
17. marts 2002 - 13:46 #7
Har lige været på weekend, derfor det sene svar!

Det overstående virker fint, så det er rigtig godt:)

Men jeg kan ikke lige finde ud af hvordan jeg får det implementeret på min hjemmeside. Jeg har vote funktionen liggende i en venstrestillet menu. Den venstrestillede menu kan ses på alle sider, så når der er stemt en gang, skal resultatet jo kunne ses på alle siderne.

Er det noget du kan finde ud af??


Justdoit:)
Avatar billede justdoit Nybegynder
18. marts 2002 - 10:59 #8
Da du ikke har svarret på det sidste spørgsmål flytter jeg den del over i et nyt! Det hedder Kald scriptet?
Avatar billede coltau Juniormester
18. marts 2002 - 12:35 #9
Det er jo også 2 forskellige ting.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester