给你一段学生注册并写入数据库的代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<%
dim rs,rs2,conn,DBPath
dim selSQL,insSQL,CID
Set conn = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("pinjiao.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
%> 
<%
if request.form("name")<>"" and request.form("pass")<>"" then
selSQL="SELECT * FROM class WHERE class='" & request.form("selZY") & "' and year='" & request.form("selYear") & "'"
set rs2=conn.execute(selSQL)
if rs2.eof then '如果在班级数据表中找不到相应班级记录,则结束本页,回到前一页面重新注册
response.write "<center>对不起,你所选择的入学年不正确,请回到前一页面重新填写"
response.write "<input type=button value=返回 onclick=history.go(-1)></center>"
response.end()
else
selSQL= "select * from student where SNO='" & request.form("SNO") & "'"
set rs=conn.execute(selSQL)
if not rs.eof then '如果在学生表中已经存在此学生信息(即学号相同),则结束本页,回到前一页面重新注册
response.write "<center>对不起,你所填的学生信息已经存在,请回到前一页面重新填写"
response.write "<input type=button value=返回 onclick=history.go(-1)></center>"
response.end()
else '否则条件满足则把此学生信息填入到学生数据表中
CID=rs2("ID")
insSQL="INSERT INTO student(name,password,CID,SNO,about) values('" & request.form("name") & "','" & request.form("password") & "'," & CID & ",'" & request.form("SNO") & "','" & request.form("about") & "')"
conn.execute(insSQL)
response.write "<center>你的信息注册成功!请回到登录页面,用你的学号和密码登录后进行投票<br>"
response.Write "<a href='student.htm'>登录页面</a>"
response.end()
end if
rs.close : set rs=nothing
end if
rs2.close : set rs2=nothing
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>学生登录</title>
<STYLE type=text/css>
.no1 {font-size: 14pt}
.no2 {font-size: 11pt}
A:link {COLOR: #FF00FF; FONT-SIZE: 9pt; TEXT-DECORATION: none}
A:visited {COLOR: black; FONT-SIZE: 9pt; TEXT-DECORATION: none}
A:active {FONT-SIZE: 9pt; TEXT-DECORATION: none}
A:hover {COLOR: red; FONT-SIZE: 9pt; TEXT-DECORATION: underline}
</STYLE>
<script language="JavaScript">
function keyenter(objForm)
{
//alert(event.keyCode);
if (event.keyCode==13) ChickIt();
}function ChickIt()
{
if (form1.name.value.length==0)
{
      alert("必须填写学生姓名!");
      focusto(0);
      return;
}
if(form1.selZY.value=="")
{
alert("必须选择专业");
focusto(1);
return;
}
if(form1.selYear.value=="")
{
alert("必须选择你的入学年");
focusto(2);
return;
}
 if (form1.SNO.value.length==0)
     {
alert("必须填写学生学号!");
     focusto(3);
     return;
}
if(form1.pass.value.length==0)
{
alert("必须填写密码");
focusto(4);
return;
}
if(form1.password.value.length==0)
{
alert("必须填写确认密码");
focusto(5);
return;
}
if(form1.password.value!=form1.pass.value)
{
alert("您两次输入的密码不相同!请重新输入密码。");
form1.pass.value="";form1.password.value="";
focusto(4);
return;
}
  form1.submit();
}
 
function focusto(x)
{
document.form1.elements[x].focus();
}
</script>
</head>

解决方案 »

  1.   

    接着上面:
    <BODY bgColor=#ffffff leftMargin=0>
    <TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=780>
      <TBODY>
      <TR>
        <TD><IMG height=18 src="image/top.gif" width=780></TD>
      </TR>
    </TBODY></TABLE>
    <TABLE align=center background=image/bgline.gif border=0 cellPadding=0 cellSpacing=0 width=780>
      <TBODY> 
      <TR align=center vAlign=top> 
          <TD height=36> 
            <h1><font color="#660033">学生注册页面</font></h1></TD>
        </TR></TBODY></TABLE>
    <TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=780>
      <TBODY> 
      <TR>
        <TD width=44><IMG height=26 src="image/daoleft.gif" width=44></TD>
          <TD background=image/daoline.gif width=684>&nbsp;</TD>
        <TD width=45><IMG height=26 src="image/daoright.gif" 
      width=52></TD>
      </TR></TBODY></TABLE>
    <table align=center background=image/bgline2.gif border=0 cellpadding=0 
    cellspacing=0 width=780>
      <tbody>
        <tr> 
          <td height="31" valign=top width=54>&nbsp;</td>
          <td width=476 height="31"><font color="#3366FF" size="2">您的位置&gt;&gt;<a href="index.htm">首页</a>&gt;&gt;学生注册</font></td>
          <td width=250>&nbsp;</td>
        </tr>
      </tbody>
    </table>
    <table align=center background=image/bgline2.gif border=0 cellpadding=0 
    cellspacing=0 width=780>
      <tr align="center"> 
        <td height="271" valign=top width=770> 
          <p>
      <table width="90%" border="0">
            <tr>
              <td><hr align="center" color="#FFCC00">
              </td>
            </tr>
          </table>
          <table width="82%" >
            <tr> 
              <td><center>
                  <font color="#FF3399">(带*的为必须填写的部分)</font>
    </center>
      <hr align="center" color="#FFCC00" width="60%" size="1">
      </td>
            </tr>
            <tr>
              <td height="211">
    <table width="87%" align="center" >
                  <tr> 
                    <td><form name="form1" method="post" action="" onKeyDown="keyenter()">
                        <table width="85%" align="center" >
                          <tr> 
                            <td width="38%"><div align="right" class="no2">姓名:</div></td>
                            <td width="62%"><label> 
                              <input name="name" type="text" size="12" maxlength="8" style="border-width:1;border-style:solid;border-color:#66CCFF" onMouseOver="this.focus()">
                              <font color="#FF3399">*</font> </label></td>
                          </tr>
                          <tr> 
                            <td><div align="right" class="no2">所在专业:</div></td>
                            <td><label> 
                              <select name="selZY" style="border-width:1;border-style:solid;border-color:#66CCFF;BACKGROUND-COLOR: #d9dcff; COLOR: rgb(60,100,128); FONT-SIZE: 9pt">
                                <option selected value="">选择专业</option>
    <%
    selSQL="select distinct class from class"
    set rs=conn.execute(selSQL)
    while not rs.eof
    response.write "<option value='" & rs("class") & "'>" & rs("class") & "</option)>"
    rs.movenext
    wend
    rs.close : set rs=nothing
    %>
                              </select>
                              </label> <font color="#FF3399">*</font> </td>
                          </tr>
                          <tr> 
                            <td><div align="right" class="no2">入学年:</div></td>
                            <td><label> 
                              <select name="selYear" style="border-width:1;border-style:solid;border-color:#66CCFF;BACKGROUND-COLOR: #d9dcff; COLOR: rgb(60,100,128); FONT-SIZE: 9pt">
                                <option selected value="">选择年</option>
                                <option value="1996">1996</option>
                                <option value="1997">1997</option>
                                <option value="1998">1998</option>
                                <option value="1999">1999</option>
                                <option value="2000">2000</option>
                                <option value="2001">2001</option>
                                <option value="2002">2002</option>
                                <option value="2003">2003</option>
                                <option value="2004">2004</option>
                                <option value="2005">2005</option>
                                <option value="2006">2006</option>
                                <option value="2007">2007</option>
                                <option value="2008">2008</option>
                                <option value="2009">2009</option>
                                <option value="2010">2010</option>
                                <option value="2011">2011</option>
                              </select>
                              </label> <font color="#FF3399">*</font> </td>
                          </tr>
                          <tr> 
                            <td><div align="right" class="no2">学号:</div></td>
                            <td><label> 
                              <input name="SNO" type="text" size="10" maxlength="10" style="border-width:1;border-style:solid;border-color:#66CCFF">
                              <font color="#FF3399">*</font> </label></td>
                          </tr>
                          <tr>
                            <td><div align="right" class="no2">密码:</div></td>
                            <td class="no2"><input name="pass" type="password" id="pass" style="border-width:1;border-style:solid;border-color:#66CCFF" size="10" maxlength="10">
                              <font color="#FF3399">*</font> (不得超过10个字符)</td>
                          </tr>
                          <tr> 
                            <td><div align="right" class="no2">确认密码:</div></td>
                            <td class="no2"><input name="password" type="password" id="password" style="border-width:1;border-style:solid;border-color:#66CCFF" size="10" maxlength="10"> 
                              <font color="#FF3399">*</font> (再次输入密码确认)</td>
                          </tr>
                          <tr> 
                            <td><div align="right" class="no2">概述:</div></td>
                            <td class="no2">(不得超过100字)</td>
                          </tr>
                          <tr> 
                            <td colspan="2"><div align="center"> 
                                <p> 
                                  <label class="no2"> 
                                  <textarea name="about" cols="35" rows="5" style="border-width:1;border-style:solid;border-color:#66CCFF"></textarea>
                                  </label>
                                </p>
                                <p> 
                                  <input type="button" value="插入记录" onClick="ChickIt()">
                                  &nbsp; 
                                  <input name="reset" type="reset" value="重新填写" onClick="focusto(0)">
                                </p>
                              </div></td>
                          </tr>
                        </table>
                      </form></td>
                  </tr>
                </table></td>
            </tr>
          </table>
          
        </td>
      </tr></table>
    <TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=780>
      <TBODY>
      <TR>
          <TD><IMG height=18 src="image/botomline.gif" width=780></TD>
      </TR></TBODY></TABLE>
    <table align=center border=0 cellpadding=0 cellspacing=0 width=780>
      <tbody> 
      <tr> 
        <td><img height=36 src="image/botom.gif" 
    width=780></td>
      </tr>
      </tbody>
    </table>
    </BODY></HTML>