Hejsan! <code>Röstningsscript
Jag håller på med ett script, där man röstar på skämt mellan 1-10!
Jag vill att om inga röst har skett så ska den ha INSERT INTO
annars ska den updatera rösterna!
Jag har försökt göra en men den e fel!
Skulle nån kunna vara snäll o rätta den till mig, vore jättetacksam!
Så här ser min kod ut!:
<% If Request.Querystring("rosta") = "skamt" Then %>
<% Session.lcid = 1053
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=db025_db1"
If Request.Cookies(Request.Querystring("id")) = "true" Then
Response.Redirect "bilder_skamt.asp?ID=" & Request.Querystring("id") & "&show=fusk"
Else
Set RecSet = Conn.Execute("SELECT * From skamt Where id=" & Request.Querystring("id"))
vote = Request.QueryString("vote")
If Recset.EOF Then
Conn.Execute("Insert Into skamt summa=summa+" &vote &" Where id=" & Request.Querystring("id"))
Conn.Execute("Insert Into skamt summa=summa+" &vote &" Where id=" & Request.Querystring("id"))
Conn.Execute("Insert Into skamt totalt=totalt+1 Where id= " & Request.Querystring("id"))
Conn.Execute("Insert Into skamt V"&vote&"=V"&vote&"+1 Where id=" & Request.Querystring("id"))
Conn.Execute("Insert Into skamt snitt ="& RecSet("summa")&"/"&RecSet("totalt")&" Where id=" & Request.Querystring("id"))
Else
Conn.Execute("Update skamt Set summa=summa+" &vote &" Where id=" & Request.Querystring("id"))
Conn.Execute("Update skamt Set totalt=totalt+1 Where id= " & Request.Querystring("id"))
Conn.Execute("Update skamt Set V"&vote&"=V"&vote&"+1 Where id=" & Request.Querystring("id"))
Conn.Execute("Update skamt Set snitt ="& RecSet("summa")&"/"&RecSet("totalt")&" Where id=" & Request.Querystring("id"))
RecSet.Close
Conn.Close
Response.Cookies(Request.Querystring("id")) = "true"
Response.Cookies(Request.Querystring("id")).Expires = DateAdd("h", 1, now)
Response.Redirect "bilder_skamt.asp?ID=" & Request.Querystring("id")
End If
End If
%>
Hassan FakhroSv: Röstningsscript
<%
Const adOpenKeyset = 1
Const adLockOptimistic = 3
If Request.Querystring("rosta") = "skamt" Then
Session.lcid = 1053
If Request.Cookies(Request.Querystring("id")) = "true" Then
Response.Redirect "bilder_skamt.asp?ID=" & Request.Querystring("id") & "&show=fusk"
Else
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=db025_db1"
Set RecSet = Server.CreateObject("ADODB.Recordset")
RecSet.Open "SELECT * FFROM skamt WHERE id=" & Request.Querystring("id"), Conn, adOpenKeyset, adLockOptimistic
vote = Request.QueryString("vote")
If Recset.EOF Then
RecSet.AddNew
RecSet("id") = Request.Querystring("id")
RecSet("totalt") = 1
RecSet("summa") = vote
For Index = 1 to 10
If Index = vote Then
RecSet("V" & Index) = 1
Else
RecSet("V" & Index) = 0
End If
Next
RecSet("snitt") = vote
RecSet.Update
Else
RecSet("totalt") = RecSet("totalt") + 1
RecSet("summa") = RecSet("summa") + vote
RecSet("V" & vote) = RecSet("V" & vote) + 1
RecSet("snitt") = RecSet("summa") / RecSet("totalt")
RecSet.Update
End If
RecSet.Close
Conn.Close
Response.Cookies(Request.Querystring("id")) = "true"
Response.Cookies(Request.Querystring("id")).Expires = DateAdd("h", 1, now)
Response.Redirect "bilder_skamt.asp?ID=" & Request.Querystring("id")
End If
End If
%>
</code>