⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addhw.asp

📁 图书管理系统功能完善,界面美观.这是基于ASP做的一个简单的系统,同大家一起分享.
💻 ASP
字号:
<%
'如果用户没有登陆,则终止响应
if session("admin_name")="" then response.end
	'记录集对象
set rs=server.createobject("adodb.recordset")
%>
<!--#include file="conn.asp"-->
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<link href=../style.css rel=stylesheet type=text/css>
</head>

<%
'如果进行的是保存操作
if request("action")="save" then
	'获得表单输入的各个字段
    hw_name=request("hw_name")
    hw_content=request("hw_content")
    hw_cash=request("hw_cash")
    hw_pic=request("hw_pic")
    sort_id=request("sort_id")
    hw_oldcash=request("hw_oldcash")

	'货物的价格应该为数字
    if not(isnumeric(hw_cash)) then
		errmsg="<br>"+"<li>货物的价格应该为数字"
		founderr=true
    end if

	'商品的价格不能为空
    if hw_cash="" then
		errmsg=errmsg+"<br>"+"<li>货物价格不能为空"
		founderr=true
    end if
    
	'货物名称不能为空
    if hw_name="" then
		errmsg=errmsg+"<br>"+"<li>货物名称不能为空"
		founderr=true
    end if
    
	'商品的介绍不能为空
    if hw_content="" then
		errmsg=errmsg+"<br>"+"<li>货物介绍不能为空"
		founderr=true
    end if
    
	'商品的类别不能为空
    if sort_id="" then
		errmsg=errmsg+"<br>"+"<li>货物类别不能为空"
		founderr=true
    end if
    
	'货物的原价应该为数字
    if not(isnumeric(hw_oldcash)) then
		errmsg="<br>"+"<li>货物的原价应该为数字"
		founderr=true
    end if

	'商品的原价不能为空
    if hw_oldcash="" then
		errmsg=errmsg+"<br>"+"<li>货物原价不能为空"
		founderr=true
    end if
    
    '商品的示例图片
    if hw_pic="" then hw_pic="images/noimage.gif"
    
	'如果发现了错误,则进行错误处理
    if founderr=true then
		'显示错误消息
		response.write errmsg

		'显示返回超级链接
		response.write "<br>"
		response.write "<a href=addhw.asp>返回</a>"
		response.end
    else
		'对字符串中的html编码进行处理
		hw_name=server.htmlencode(hw_name)
		hw_content=server.htmlencode(hw_content)
		hw_pic=server.htmlencode(hw_pic)

		'用html符号替换字符串中的空格和回车字符
		hw_name=replace(hw_name," ","&nbsp;")
		hw_name=replace(hw_name,chr(13)&chr(10),"<br>")
		
		hw_content=replace(hw_content," ","&nbsp;")
		hw_content=replace(hw_content,chr(13)&chr(10),"<br>")		
		    
		'产讯hw数据表
		sql="select * from hw"
		'打开记录集
		rs.open sql,conn,3,3

		'添加一条新的记录
		rs.addnew
		rs("hw_name")=hw_name
		rs("hw_content")=hw_content
		rs("hw_cash")=hw_cash
		rs("sort_id")=sort_id
		rs("hw_oldcash")=hw_oldcash
		rs("hw_pic")=hw_pic

		'更新数据库
		rs.update
    end if
    
	'提示用户添加商品成功
	'显示返回超级链接
    response.write "货物添加成功"
    response.write "<br>"
    response.write "<a href=addhw.asp>返回</a>"

	'关闭记录集
    rs.close
else
	'添加商品的表单
%>
<table border="0" width="100%" cellspacing="1">
  <tr>
    <td width="100%">
      <form method="post" action="addhw.asp?action=save">
		<table border="0" width="100%" cellspacing="1">
		  <tr>
		    <td width="100%">商品类别<select size="1" name="sort_id">
<%
	'查询sort数据表,获得所有商品类别
	sql="select * from sort"
	'打开记录集
	rs.open sql,conn,3,3

	'如果记录集为空
	if rs.eof then
%>
	<option value=""></option>
<%
	else
		'否则,循环将商品类别加入到下拉列表中
		do while not rs.eof
%>
	<option value="<%=rs("sort_id")%>"><%=rs("sort_name")%></option><%rs.movenext
		loop
	end if
	rs.close
%>
	</select></td>
		  </tr>
		  <tr>
		    <td width="100%">商品名称<input type="text" name="hw_name" size="20" class=input></td>
		  </tr>
		  <tr>
		    <td width="100%">商品原价<input type="text" name="hw_oldcash" size="20" class=input></td>
		  </tr>
		  <tr>
		    <td width="100%">商品价格<input type="text" name="hw_cash" size="20" class=input><font color="#ff0000">不支持小数,小数点后四舍五入</font></td>
		  </tr>
		  <tr>
		    <td width="100%">商品介绍</td>
		  </tr>
		  <tr>
		    <td width="100%"><textarea rows="9" name="hw_content" cols="77" class=input></textarea></td>
		  </tr>
		  <tr>
		    <td width="100%">商品图片<input type="text" name="hw_pic" size="46" class=input></td>
		  </tr>
		</table>
		<p><input type="submit" value="提交" name="b1" class=input><input type="reset" value="全部重写" name="b2" class=input></p>
      </form>
       <iframe name="ad" frameborder=0 width=100% height=50 scrolling=no src=upload.asp></iframe> </td>
  </tr>
</table>
<%
end if

'释放记录集对象
set rs=nothing

'关闭数据库连接,释放对象
conn.close
set conn=nothing
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -