📄 save_news.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
'合法性检查
if session("flag")=false then
response.write("<script>window.alert('登录超时,请重新登录!');window.open('index.htm','_self')</script>")
response.end()
response.clear()
end if
if request.Cookies("username")="" then
response.write("<script>window.alert('登录超时,请重新登录!');window.open('index.htm','_self')</script>")
response.end()
response.clear()
end if
'插入数据
'判断执行的动作为添加
if request("action")="add" then
if len(replace(Trim(Request.Form("news_title")),"'",""))=0 then
response.write("<script>window.alert('新闻标题没有填写!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_content")),"'",""))=0 then
response.write("<script>window.alert('新闻内容没有填写!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_intro")),"'",""))=0 then
response.write("<script>window.alert('新闻简介内容没有填写!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_intro")),"'",""))>100 then
response.write("<script>window.alert('新闻简介内容过长!');history.go(-1);</script>")
response.end()
response.clear()
end if
'添加数据
set rs= Server.CreateObject("ADODB.Recordset")
sqltxt="select * from news"
rs.open sqltxt,conn,1,3
rs.addnew
rs("news_title")=replace(Trim(Request.Form("news_title")),"'","")
rs("news_content")=replace(Trim(Request.Form("news_content")),"'","")
rs("news_depart")=replace(Trim(Request.Form("news_depart")),"'","")
if replace(Trim(Request.Form("stress")),"'","")="1"then
rs("stress")="1"
end if
rs("news_intro")=replace(Trim(Request.Form("news_intro")),"'","")
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write("<script>window.alert('新闻添加成功!');history.go(-1);</script>")
end if
'添加信息结束
'判断执行的动作为编辑
if request("action")="edit" then
if len(replace(Trim(Request.Form("news_title")),"'",""))=0 then
response.write("<script>window.alert('新闻标题没有填写!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_content")),"'",""))=0 then
response.write("<script>window.alert('新闻内容没有填写!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_intro")),"'",""))<10 then
response.write("<script>window.alert('新闻简介内容过短!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_intro")),"'",""))>20 then
response.write("<script>window.alert('新闻简介内容过长!');history.go(-1);</script>")
response.end()
response.clear()
end if
if len(replace(Trim(Request.Form("news_intro")),"'",""))=0 then
response.write("<script>window.alert('新闻简介没有填写!');history.go(-1);</script>")
response.end()
response.clear()
end if
set rs= Server.CreateObject("ADODB.Recordset")
sqltxt="select * from news where id="&request.form("news_id")
rs.open sqltxt,conn,1,3
rs("news_title")=replace(Trim(Request.Form("news_title")),"'","")
rs("news_content")=replace(Trim(Request.Form("news_content")),"'","")
rs("news_depart")=replace(Trim(Request.Form("news_depart")),"'","")
if replace(Trim(Request.Form("stress")),"'","")="1"then
rs("stress")=1
else
rs("stress")=0
end if
rs("news_intro")=replace(Trim(Request.Form("news_intro")),"'","")
rs.update
style="VbYesNo"&"VbInformation"
title="信息修改成功"
ctxt=1000
response.write("<script language=vbscript>msgbox("&rs("news_title")&","&style&","&title&","&ctxt&")</script>")
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
'信息修改结束
'判断执行的动作为强调设置
if request("action")="stress"then
if request("stress_id")="0" then
stress_txt="update news set stress=1 where id="&request("news_id")
stress_txt_info="此新闻已设置为强调"
else
stress_txt="update news set stress=0 where id="&request("news_id")
stress_txt_info="此新闻已设置为不强调"
end if
conn.execute stress_txt
conn.close
set conn=nothing
response.write("<script>window.alert('"&stress_txt_info&"!');window.location.href='manage_news.asp';</script>")
end if
'强调设置结束
'判断执行动作为删除
if request("action")="del" then
deltxt="delete from news where id ="&request("news_id")
conn.execute deltxt
conn.close
set conn=nothing
response.write("<script>window.alert('新闻删除成功!');window.location.href='manage_news.asp';</script>")
end if
'删除动作结束
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -