---
title: "Nollställ.?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/5497-nollställ"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "cgi"
published: "2000-03-25T15:16:00.000Z"
updated: "2000-03-26T14:54:00.000Z"
replies: 6
views: 197
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/5497-nollställ"
---

# Nollställ.?

## #1 — cgi, 2000-03-25T15:16Z

Har ett röstningssystem på sidan, men vet ej hur man nollställer scriptet.???
Så här ser koden ut:

```

<% 
' Här skapar vi en dsn-less connection mot vote.asp
Set Connect=server.CreateObject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("vote.mdb")
Connect.Open DSNtemp
%>

<%
'Two varibles are passed into the db
'u_input is the value if the user entered a response to
'the vote/poll question....IP is the address of the user
u_input=request.form("u_input")
u_ip=request.servervariables("remote_addr")

' if the user did not enter anything in the poll on this visit
' then display the poll question and possible choices
if u_input = "" then
%>

<form method="post" action="<%= request.servervariables("script_name") %>">

<%
else
' if the user did input a choice on the vote/ballot
' check to see if their ip address is already in the db
accessdb="votes_db" 
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
sql = "select ip from ballot where ip ='" & u_ip & "'"

rs.Open sql, cn
if rs.eof then
' if the user has not voted previously indicate it
been_here_before="No"
end if
rs.close

if been_here_before = "No" then
' Since the user has not voted previously their input
' their vote will be added to the db

sql = "insert into ballot (ip, selection" & u_input &") "
sql = sql & "values ('" & u_ip & "',1)"
rs.Open sql, cn
end if

'This will summerize and count the records in the db
sql= "select distinctrow sum(selection1) as sum_selection1, " 
sql= sql & "sum(selection2) AS sum_selection2, sum(selection3) AS sum_selection3, "
sql= sql & "sum(selection4) AS sum_selection4, count(*) AS total_votes "
sql= sql & "FROM ballot;"
rs.Open sql, cn
total1=rs ("sum_selection1")
total2=rs ("sum_selection2")
total3=rs ("sum_selection3")
total4=rs ("sum_selection4")
count=rs ("total_votes")
%>
A<img src="red.jpg" height="10" width="<%= (total1/count)*100 %>">
<%= formatnumber((total1/count)*100,1)  %>%<br>
B<img src="yellow.jpg" height="10" width="<%= (total2/count)*100 %>">
<%= formatnumber((total2/count)*100,1)  %>%<br>
C<img src="green.jpg" height="10" width="<%= (total3/count)*100 %>">
<%= formatnumber((total3/count)*100,1)  %>%<br>
D<img src="blue.jpg" height="10" width="<%= (total4/count)*100 %>">
<%= formatnumber((total4/count)*100,1)  %>%<br>
Totalt har: <%= formatnumber(count,0,0) %>st röstat.<br>
 
<% if been_here_before <> "No" then %>
OBS! du har röstat förut så den här rösten räknades <u>inte</u> 
<% else %>
Din röst har laggts till....
<% end if %>
<br>
Din IP address <%= u_ip %>
<% end if %>
```

Tacksam för hjälp.

Permalänk: https://www.webforum.nu/p/5497

## #2 — a, 2000-03-25T15:49Z

Töm databasen (vote.mdb)

Permalänk: https://www.webforum.nu/p/242293

## #3 — cgi, 2000-03-25T17:04Z

Visst skulle jag kunna göra det, men nu är det så här att databasen inte går att öppna på nåt konstigt sätt.
Fråga mig inte varför.

Permalänk: https://www.webforum.nu/p/242294

## #4 — bohlin, 2000-03-25T19:03Z

databasen är kanske en access 2000 databas, och du har kanske bara access97. 
DELETE \* FROM poll borde väl funka?

Permalänk: https://www.webforum.nu/p/242295

## #5 — cgi, 2000-03-25T21:41Z

Vad menar du med DELETE \* FROM poll.???

Permalänk: https://www.webforum.nu/p/242296

## #6 — bohlin, 2000-03-26T13:49Z

gör en ny fil, tex töm_databas.asp och stoppa i denna koden...borde funka.

Set Connect=server.CreateObject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (\*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("vote.mdb")
Connect.Open DSNtemp
set rs = server.createobject("ADODB.Recordset")
sql = "DELETE \* FROM poll"
rs.Open sql, connect

Permalänk: https://www.webforum.nu/p/242297

## #7 — cgi, 2000-03-26T14:54Z

Nej du det funkar inte.

Permalänk: https://www.webforum.nu/p/242298

---

Tråden på webben: https://www.webforum.nu/amne/asp/5497-nollställ
