<!--#include file="conn/zkconn.asp" -->
<%
conn.execute("Delete ls_cart where datediff(n,sj,getdate())>200")
conn.execute("Delete ls_userid where datediff(n,sj,getdate())>200")



'如果是要购买某产品
if clng(request("cpid"))<>"" then
set rs = conn.execute("select * from chanpin where id="&cint(request("cpid"))&"")
  if not rs.eof then
	mc=rs("mc")
	userid=rs("userid")
	jg1=rs("jg1")
	jg2=rs("jg2")
	xt=rs("xt")
    rs.close
  end if
  set rs = conn.execute("select * from ls_cart where cpid="&cint(request("cpid"))&" and sessionid="&session.sessionid&"")
'如果临时购物车无这个session买的这个产品，就加入临时购物车
  if rs.eof then
    conn.execute("Insert into ls_cart(cpid,mc,jg1,jg2,xt,userid,sessionid,sj)values("&cint(request("cpid"))&",'"&mc&"',"&jg1&","&jg2&",'"&xt&"',"&userid&","&session.sessionid&",'"&now()&"')")
    set rs1 = conn.execute("select * from ls_userid where userid="&userid&" and sessionid="&session.sessionid&"")
    if rs1.eof then
    conn.execute("Insert into ls_userid(userid,sessionid,sj)values("&userid&","&session.sessionid&",'"&now()&"')")
    else
    conn.execute("Update ls_userid set sj='"&now()&"' where  userid="&userid&" and sessionid="&session.sessionid&"")
    end if
    rs1.close
    set rs1=nothing
'如果临时购物车有这个session买的这个产品，就更新时间和数量
  else
conn.execute("Update ls_cart set sl=sl+1,sj='"&now()&"' where  cpid="&request("cpid")&" and sessionid="&session.sessionid&"")
conn.execute("Update ls_userid set sj='"&now()&"' where  userid="&userid&" and sessionid="&session.sessionid&"")
  end if
rs.close
set rs=nothing
end if
Response.redirect "cart.asp"
%>