当前位置: 代码迷 >> ASP >> 请教这段代码错在哪儿了
  详细解决方案

请教这段代码错在哪儿了

热度:66   发布时间:2012-09-04 14:19:30.0
请问这段代码错在哪儿了?
HTML code

<%
'date signtime = formatdatetime(now,2)
'response.Write(signtime)
'Year(now())
'Month(now())
'day(now())


set conn=server.CreateObject("adodb.connection")
DBPath = Server.MapPath("/signin/20120720.mdb")
conn.open "provider=microsoft.jet.oledb.4.0; data source="&DBpath

set rs=conn.execute ("select time as st from sign where username = '"&username&"'")
str =""
if rs.eof then
set rs=conn.execute ("insert into sign (username) Values ('"&username&"')")


If DateDiff("h",CDate(st),st) > 24 then '这里我还不知道怎么比较
%>
        <script language="JavaScript">
          alert("今日已经签到!")
          history.go(-1)
        </script>
<%
else
sql = "update sign set times = times + 1 and time =  '"&Year(now())-Month(now())-day(now())&"' where username = "&username&"'"
conn.execute (sql)
%>
        <script language="JavaScript">
          alert("签到成功!")
          history.go(datecheck.asp)
        </script>
<%
end if
end if
%>



代码的想法很简单,就是点击按钮签到一次,username已经获取了,在一个mdb中记录,24小时内签到一次,麻烦大神帮我改改~

------解决方案--------------------
VBScript code

<%

username = "xxxx"

Set conn = CreateObject("adodb.connection")
DBPath = Server.MapPath("/signin/20120720.mdb")
conn.open "provider=microsoft.jet.oledb.4.0; data source="& DBPath
sql = "SELECT [username], [time], [times] FROM [sign] WHERE [username] = '" & Replace(username, "'", "''") & "'"
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sql, conn, 1, 3
If rs.EOF And rs.BOF Then
    rs.AddNew
    rs("username").Value = username
    rs("time").Value = Now()
    rs("times").Value = 1
    rs.Update
    b = True
Else
    If DateDiff("h", CDate(rs("time").Value), Now()) < 24 Then
        b = False
    Else
        b = True
        rs("time").Value = Now()
        rs("times").Value = rs("times").Value + 1
        rs.Update
    End If
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing

If b Then
%>
        <script language="JavaScript">
          alert("签到成功!")
          history.go(datecheck.asp)
        </script>
<% Else %>
        <script language="JavaScript">
          alert("今日已经签到!")
          history.go(-1)
        </script>
<% End if %> 
  相关解决方案