📄 mgstudent.asp
字号:
<%@ Language=VBScript %>
<% option explicit %>
<!--#include file="conn.asp"-->
<!--#include file="Checkadmin.asp"-->
<%
dim isedit '是否在编辑状态
dim id,studentname'定义变量,用户的id
dim sql,rs,rsc
isedit=false
if request("action")="edit" then
isedit=true
end if
if request("action")="modify" then '修改用户
set rs=server.createobject("ADODB.recordset")
if trim(request("studentpassword"))="" then
response.write "错误!密码不能为空! <a href=# onclick='javascript:window.history.go(-1)'>返回</a>"
response.end
end if
studentname=request("studentname")
rs.open "select * from student where studentname='"&studentname&"'",conn,1,3
rs("studentpassword")=request("studentpassword")
rs.update
rs.close
set rs=nothing
end if
%>
<%
if request("action")="add" then '添加新用户
if trim(request("studentname"))="" or trim(request("studentpassword"))="" then
response.write "错误!用户名或密码不能为空! <a href=# onclick='javascript:window.history.go(-1)'>返回</a>"
response.end
end if
set rs=server.createobject("adodb.recordset") '检查学生是否重名
rs.open "select * from student where studentname='" & cstr(trim(request("studentname"))) & "'",conn,1,1
if err.number <> 0 then
response.write "数据库出错"
else if not rs.bof and not rs.eof then
response.write "错误!该用学生存在! <a href=# onclick='javascript:window.history.go(-1)'>返回</a>"
response.end
end if
end if
rs.close
set rs=nothing
sql="insert into student(studentname,studentpassword) values('" & cstr(trim(request("studentname"))) & "','" & cstr(trim(request("studentpassword"))) & "')"
conn.execute sql
if err.number <> 0 then
response.write "数据库操作出错:" + err.description
else %>
<script language=vbscript>
msgbox "操作成功!新用户 <%=trim(request("studentname"))%> 的信息添加成功!"
</script>
<%end if
end if
if request("action")="del" then '删除用户
sql="delete from student where id=" &request("id")
conn.execute sql
if err.number <> 0 then
response.write "数据库操作错误:" + err.description
err.clear
else %>
<script language=vbscript>
msgbox "操作成功!用户号为<%=trim(request("id"))%>的信息已删除!"
</script>
<% end if
end if
%>
<html>
<head>
<title>管理学生</title>
<script language=javascript>
function SureDel(id)
{
if ( confirm("您确定要删除该用户吗?"))
{
window.location.href = "mgstudent.asp?action=del&id=" +id
}
}
</script>
</head>
<body background=../images/backimage.gif >
<table width="80%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor=blue>
<tr>
<td width="25%">
<div align="center">---学生姓名---</div>
</td>
<td width="20%">
<div align="center">密码</div>
</td>
<td width="20%">
<div align="center">操作</div>
</td>
</tr>
<%
set rs=server.createobject("adodb.recordset")
rs.open "select * from student ",conn,1,1
if err.number <> 0 then
response.write "数据库出错"
else
if rs.bof and rs.eof then
rs.close
response.write "目前没有学生"
else
do while not rs.eof %>
<tr>
<td width="25%" height="21" >
<div align="center"><%=rs("studentname")%></div>
</td>
<td width="20%" height="21" >
<div align="center"><%=rs("studentpassword")%></div>
</td>
<td width="20%" height="21" >
<div align="center"><a href='mgstudent.asp?studentname=<%=trim(rs("studentname"))%>&action=edit'>编辑</a>  
<%
response.write "<a href='javascript:SureDel(" & cstr(rs("id")) & ")'>删除</a>"
%>
</div>
</td>
</tr>
<% rs.movenext
loop
end if
end if
%>
</table>
<% if isedit then
set rs=server.createobject("adodb.recordset")
studentname=request("studentname")
rs.open "select * from student where studentname='"&studentname&"'",conn,1,1
response.write "<p align='center'><font size=3>编 辑 学 生 信 息</font></p>"
else
response.write "<p align='center'><font size=3>添 加 学 生 信 息</font></p>"
end if %>
<p align="center">
<form action="mgstudent.asp" method="post">
<input type="Hidden" name="action" value='<% If isedit then%>modify<% Else %>add<% End If %>'>
<%If isedit then%>
<input type="Hidden" name="studentname" value='<%=studentname%>'>
<%End If%>
用户名称:
<% if isedit then
response.write request("studentname")
else
%>
<input type="text" name="studentname" class=input maxlength=14 size="16">
<%end if%>
<br>
用户密码:<input type="password" name="studentpassword" class=input maxlength=12 size="16" value='<% if isedit then
response.write trim(rs("studentpassword"))
end if %>'><br>
<input type="submit" name="submit" value="确 定" class=button>
</form>
<p align=center><a href="primarypage.asp"><font color=red size=+0 face=楷体>返回管理界面</font></a></p>
<%
rs.close
set rs=nothing
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -