<%
dim connect, rs, sql, outrec, aid, action
set connect = server.createobject("ADODB.Connection")
connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &_
Server.MapPath("\perlphpasp\db\casereg.mdb"))
response.write("<body><form action=regist.asp method=post>")
response.write("Year:<input name=gyear value=2544>")
response.write("Semester:<input name=gsem value=2 size=5><br>")
sql = "select * from student"
set rs = connect.execute(sql)
response.write("<select name=gidstd size=5>")
do while not rs.eof
response.write("<option value="&rs("idstd")&">"&rs("idstd"))
rs.movenext
loop
response.write("</select>")
sql = "select * from subject"
set rs = connect.execute(sql)
response.write("<select name=gsubj size=5>")
do while not rs.eof
response.write("<option value="&rs("subj")&">"&rs("subj"))
rs.movenext
loop
response.write("</select>")
response.write("section:<input name=gsection value=1 size=5><br>")
response.write("<input type=submit name=action value=list> ")
response.write("<input type=submit name=action value=listall> ")
response.write("<input type=submit name=action value=regist> ")
response.write("<input type=submit name=action value=drop></form>")
gyear = request.form("gyear")
gsem = request.form("gsem")
gidstd = request.form("gidstd")
gsubj = request.form("gsubj")
gsection = request.form("gsection")
action = request.form("action")
if action = "regist" then
if gsubj = "" or gidstd = ""then
response.write("ท่านกรอกข้อมูลไม่สมบูรณ์ จึงไม่จัดเก็บ")
else
sql = "select * from regist where ryear="&gyear&" and rsem="&gsem
sql = sql + " and idstd="&gidstd&" and subj='"&gsubj&"'"
set rs = server.createobject("ADODB.recordset")
rs.open sql,connect,1,3
totrs = rs.recordcount
if totrs > 0 then
response.write("ท่านได้ลงทะเบียนไปแล้ว ลงซ้ำไม่ได้<br>")
else
sql="insert into regist(ryear,rsem,idstd,subj,section,grade)"
sql=sql+"values("&gyear&","&gsem&","&gidstd&",'"&gsubj&"',"&gsection&",4.6)"
set rs = connect.execute(sql)
response.write("จัดเก็บข้อมูลเรียบร้อย<br>")
end if
action = "list"
end if
end if
if action = "drop" then
if gsubj = "" or gidstd = ""then
response.write("ท่านกรอกข้อมูลไม่สมบูรณ์ จึงบอกเลิกวิชาไม่ได้")
else
sql = "select * from regist where ryear="&gyear&" and rsem="&gsem
sql = sql + " and idstd="&gidstd&" and subj='"&gsubj&"'"
set rs = server.createobject("ADODB.recordset")
rs.open sql,connect,1,3
totrs = rs.recordcount
if totrs = 0 then
response.write("ไม่พบวิชาที่ต้องการบอกเลิก")
else
sql = "delete from regist where ryear="&gyear&" and rsem="&gsem
sql = sql + " and idstd="&gidstd&" and subj='"&gsubj&"'"
set rs = connect.execute(sql)
response.write("ลบข้อมูลเรียบร้อย")
end if
end if
end if
if left(action,4) = "list" then
sql = "select * from regist "
if right(action,3) <> "all" and gidstd > 0 then
sql = sql + "where ryear="&gyear&" and rsem="&gsem&" and idstd="&gidstd
end if
set rs = connect.execute(sql)
rs.movefirst
do while not rs.eof
response.write(rs("ryear")&"- "&rs("rsem")&"- "&rs("idstd"))
response.write("- "&rs("subj")&"- "&rs("section")&"- "&rs("grade")&"<br>")
rs.movenext
loop
end if
connect.close
set rs = nothing
set connect = nothing
%>
จำนวน : 91 บรรทัด