<!--#include file="chkinput.asp"-->
<!--#include file="conn.asp"-->
<%
    bid=request.form("bid")
    if isempty(bid) or bid="" then bid=1
    fid=request.form("fid")
    
    if isempty(fid) or fid="" then fid=0
    password=trim(Replace(request.form("password"),"'",""))
    username=trim(Replace(request.form("username"),"'",""))
    title=trim(Replace(Request.Form("title"),vbcrlf," "))
	title=Replace(title,chr(23),"")
	title=Replace(title,chr(9),"")
	title=Replace(title,chr(8),"")
    title=Replace(title,chr(34),"")
    body=request.form("body")
    body=trim(Replace(Request.Form("body"),vbcrlf," "))
    body=Replace(body,chr(23),"")
	body=Replace(body,chr(9),"")
	body=Replace(body,chr(8),"")
    body=Replace(body,chr(34),"")
    title=server.htmlencode(title)
    faceimg=trim(request.form("faceimg"))
  
    if title="" then
response.write"<script language='javascript'>alert('对不起，帖子主题不能为空')</script>"
response.write "<script language='javascript'>history.back(-1)</script>"
response.end
end if

    if  strLength(title)>Cint("55")   then
    response.write"<script language='javascript'>alert('对不起，帖子主题不能超过25个字')</script>"
    response.write "<script language='javascript'>history.back(-1)</script>"
    end if
 

    if username="" then
    response.write"<script language='javascript'>alert('别忘了写上您的大名')</script>"
    response.write "<script language='javascript'>history.back(-1)</script>"
    end if

	
    if isempty(body) or body="" then
     response.write"<script language='javascript'>alert('内容不能为空')</script>"
response.write "<script language='javascript'>history.back(-1)</script>"
      end if
  
	
	
	if cint(fid)<>0 then
	    retype=fid
	    
	else
	    retype=0
	end if
	wdate=now()
	ldate=now()
set rs=server.createobject("adodb.recordset")
    sql="select * from member  where username='" &username& "'  "
    rs.open sql,conn,1,1
    if  rs.eof then
response.write"<script language='javascript'>alert('用户名密码错误！')</script>"
response.write "<script language='javascript'>history.back(-1)</script>"
response.end
end if
  if password<>rs("password") then
  response.write"<script language='javascript'>alert('用户名密码错误！')</script>"
response.write "<script language='javascript'>history.back(-1)</script>"
response.end
end if
    ls=session("lasttime")
if ls+1/8640>now() then
 response.write"<script language='javascript'>alert('请不要重复提交帖子')</script>"
response.write "<script language='javascript'>history.back(-1)</script>"
    end if
if fid<>0 then
	     set update=server.createobject("adodb.recordset")
	     sqlstr="select * from book where id="&fid
	     update.open sqlstr,conn
	     reply=update("reply")+1
	     update.close
	     
	     sqlstr="update book set reply=" &cint(reply)& ",ldate='" &ldate& "' where id="& fid
	     update.open sqlstr,conn
     set update=nothing
	 end if


	 
     Set cmdTemp = Server.CreateObject("ADODB.Command")
	 Set insert = Server.CreateObject("ADODB.Recordset")
	     cmdTemp.CommandText="SELECT * FROM book WHERE (title IS NULL)"
         cmdTemp.CommandType = 1
         Set cmdTemp.ActiveConnection = conn
  	     insert.Open cmdTemp, , 1, 3
	     insert.AddNew
	     insert("title")=title
	     insert("username")=username
	     
         insert("type")=retype
	     insert("fid")=cint(fid)
	     insert("bid")=cint(bid)
	     insert("faceimg")=faceimg
	     insert("wdate")=wdate
	     insert("ldate")=ldate
         insert("body")=body
         insert.update
	     session("lasttime")=Now()
         set insert=nothing
	     set cmdTemp=nothing
	    
         set update=nothing
         sql="select * from member where username='"&username&"' order by id desc" 
set rs= Server.CreateObject("ADODB.RecordSet") 
rs.Open sql, Conn, 2, 3
rs("rq")=rs("rq")+1
rs("jy")=rs("jy")+2


rs.update


	response.redirect "list.asp?bid="&bid

%>

