?? mgstudent.asp
字號:
<%@ Language=VBScript %>
<% option explicit %>
<!--#include file="conn.asp"-->
<%
dim isedit '是否在編輯狀態
dim color '表格顏色
dim id,studentname'定義變量,用戶的id
dim sql,rs,rsc
color=1
isedit=false
if request("action")="edit" then
isedit=true
end if
if request("action")="edit" then '修改用戶
if trim(request("studentpassword"))="" then
response.write "錯誤!密碼不能為空! <a href=mgstudent.asp>返回</a>"
response.end
end if
sql="update student set studentname='" & cstr(trim(request("studentname"))) & "',studentpassword='" & 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")="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("studentname"))%> 的信息已刪除!"
</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">
<%
response.write "<a href='javascript:SureDel(" & cstr(rs("id")) & ")'>刪除</a>"
%>
</div>
</td>
</tr>
<% rs.movenext
color=color+1
loop
end if
end if
'rs.close
'set rs=nothing %>
</table>
<p align="center">
<% response.write "<font size=3>添 加 新 的 學 生</font><br>" %>
<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='<%=cstr(request("studentname"))%>'>
<%End If%>
用戶名稱:<input type="text" name="studentname" class=input maxlength=14 size="16"><br>
用戶密碼:<input type="password" name="studentpassword" class=input maxlength=12 size="16"><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>
</p>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -