網路 <%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
if Request.ServerVariables("http_method")="POST" and Request.Form("submit")<>"跳到" then
'如果按POST方式提交表單內容
set conn=server.CreateObject("adodb.connection")
conn.ConnectionString="dsn=testsys"
conn.Open
strstid=Request.Form("stid")
strstname=Request.Form("stname")
if Request.Form("submit")="加入" then
'如果執行加入學生資訊的請求
strsql="select * from studentinfo where stid='" & strstid & "'"
'根據要加入的學生學號查詢資料庫的表studentinfo中是否存在該學生的記錄
set mrs1=conn.Execute(strsql)
if not(mrs1.BOF and mrs1.EOF) then
'如果要加入的學生學號已存在,則提示重新輸入資訊
Response.Write "該學號已經存在,請重新輸入學生資訊<br>"
Response.Write "<a href=taddstudent.asp?page=" & request("page") & "&stname=" & strstname & "&stid=" & strstid & ">返回</a>"
else
'如果要加入的學生學號不存在,則向資料庫中加入該學生資訊
strsql="insert into studentinfo (stname,stid) values ('" & strstname & "','" & strstid & "')"
conn.Execute(strsql)
strstid=""
strstname=""
end if
end if
if Request.Form("submit")="刪除" then
'如果是刪除學生資訊請求
strsql="delete * from studentinfo where stid='" & strstid & "'"
'刪除學生資訊
conn.Execute(strsql)
'刪除學生的考試成績
strsql="delete * from score where stid='" & strstid & "'"
conn.Execute(strsql)
strstid=""
strstname=""
end if
conn.Close
set conn=nothing
else
strstname=Request.QueryString("stname")
strstid=Request.QueryString("stid")
end if
%>
<FORM action="taddstudent.asp" method=POST id=form1 name=form1>
<P><FONT face="幼圓" size=3 color=Crimson>學生資訊</FONT><BR>
<FONT face="" size=3>姓名:
<INPUT id=stname name=stname value=<%=strstname%>></FONT><BR>
<FONT face="" size=3>學號:
<INPUT id=stid name=stid value=<%=strstid%>></FONT>
<FONT face="" size=3>
<INPUT id=submit1 name=submit type=submit value=加入>
<INPUT id=submit2 name=submit type=submit value=刪除>
</FONT></P><FONT face="" size=3>
<HR>
</FONT>
<P>
<TABLE border=0 cellPadding=1 cellSpacing=1 width=75%>
<TR bgcolor=Honeydew>
<TD>姓名</TD>
<TD>學號</TD></TR>
<%
set mrs=server.CreateObject("adodb.recordset")
mrs.ActiveConnection="dsn=testsys"
mrs.Source="select