日期:2014-05-17  浏览次数:21204 次

一个点击确定同时校验账号信息的小功能.有点小错.来看看咯.
<%@LANGUAGE=VBSCRIPT%>
<!--#include   file= "conn.asp "-->
<head>
<%
sub   checkaddadmin()
        Userid=Request.Form( "userid ")
PassWord=Request.Form( "PassWord ")
if   userid   = " "   or   PassWord   = " "   then
Response.Write " <font   color=red> 请输入完整的管理员信息! </font> "
                else
set   rs=server.createobject( "adodb.recordset ")
sql= "select   *   from   adminuser "
rs.open   sql,conn,1,3
rs.addnew
rs( "userid ")=trim(request( "userid "))
rs( "password ")=trim(request( "password "))
rs.update
rs.close
set   rs=nothing
conn.close
set   conn=nothing
response.write   "管理员添加成功,点击[ <a   href=index.asp> 返回 </a> ]返回首页查看 "
                end   if
end   sub

%>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 添加管理员 </title>
</head>

<body>
<form   name= "addadm "   method= "post "   action= " ">
    <label>
      <input   type= "text "   name= "userid ">
    </label>
    ====请在这里输入要添加的管理员的用户名
    <p>
        <label>
        <input   type= "password "   name= "password ">
        </label>
    =====请在这里输入要添加的管理员的密码 </p>
    <p>
        <label>
        <input   name= "submit "   type= "submit "   id= "submit "   value= "添加 "   OnClick= "checkaddadmin ">
        </label>
    </p>
</form>

</body>
</html>

想法是给我自己的数据库加入一个管理员.

但是呢.希望有个校验过程.

主义了checksub,没有在页面下方调用.要是调用了.用会直接显示条件1,

要是不调用呢....嘿嘿.哪个条件都不显示了.正确输入可以插入信息.

但是留空也不插入也不报错..呵呵.怎么做能让他报错呢?

新手.多帮忙.

------解决方案--------------------
很负责的说
你的代码相当的不规范,还是帮你改好吧


<%@LANGUAGE=VBSCRIPT%>
<!--#include file= "conn.asp "-->
<head>
<%
sub checkaddadmin()
Dim Userid,PassWord,Sql
If Request.Form( "ok ")= " " Then Exit Sub
Userid=Trim(Request.Form( "userid "))
PassWord=Trim(Request.Form( "password "))
if userid = " " or PassWord = " " then
Response.Write " <font color=red> 请输入完整的管理员信息! </font> "
else
'判断管理员存在。。
Sql= "Select * Form [AdminUser] Where Userid= ' "& Replace(Userid, " ' ", " ' ' ") & " ' "
If Not Conn.Execute(Sql).Eof Then
Response.Write " <font color=red> ID "& Userid & "存在! </font> "
Else
Sql= &q