<%
	sub executeUpdate(db,query)
		dim con
		err.clear
		on error resume next
		set con=server.createObject("adodb.connection")
		con.open db

		con.execute query

		con.close
		set con=nothing
		response.write err.description
    end sub

    '------------------------------------
	function fselect(db,query)
		dim rs
		set con=server.createObject("adodb.connection")
		con.open db
		set rs=server.createObject("adodb.recordset")

		rs.CursorLocation= 3 ' adUseClient

		rs.open query,con

		set fselect=rs

		set rs.activeconnection=nothing

		set fselect=rs
		con.close
		set con=nothing
    end function
	'------------------------------------
	function countOf(id)
		dim rs,count
		set rs=fselect(Application("Product"),"select count(*) from basket where ids='" & Session.SessionID & "' and idp=" & request("id"))
		while not rs.eof
			if rs.bof then break
			count=rs(0)
			rs.moveNext
		wend
		rs.close
		set rs= nothing
		countOf= count
	end function
	'---------------------------------------
	Response.write "insert into basket (ids,idp,count) values('" & Session.SessionID & "'," & request("id") & ",1)"
	
	if countOf(request("id"))<1 then
    	executeUpdate  Application("Product") ,"insert into basket (ids,idp,count1) values('" & Session.SessionID & "'," & request("id") & ",1)"
	else
		executeUpdate Application("Product") ,"update basket set count1=count1+1 where ids='" & Session.SessionID & "' and idp=" & request("id")
	end if
		
	response.redirect("viewbasket.asp")
%>