asp 怎样改提交表单前进行数据验证
请问高手下面的代码怎么改能实现表单提交前验证用户名与序列号同数据库中的tblgsm表的gsm段相符。相符后才能提交表单,不相符给出错误提示。谢谢<!--#includef...
请问高手下面的代码怎么改能实现表单提交前验证用户名与序列号同数据库中的tblgsm表的gsm段相符。相符后才能提交表单,不相符给出错误提示。谢谢
<!-- #include file="common.asp" -->
</HEAD>
<%
If Request("action") = "savenew" Then
Set Rs1 = Server.CreateObject("Adodb.Recordset")
strSql = "Select * from tblSell where (id is null)"
Rs1.Open StrSql, Conn, 3, 3
Rs1.AddNew
Rs1("Gsm1") = Request("Gsm1")
Rs1("GsmName1") = Request("GsmName1")&Request("GsmName2")&Request("GsmName3")&Request("GsmName4")
Rs1("FirstName") = Request("FirstName")
Rs1("Phone") = Request("Phone")
Rs1.Update
Rs1.Close
Call OutScriptLoc("alert('您的资料已经成功提交.')","jszx.asp")
Response.End
End If
%>
<BODY topmargin=0 >
<table width="100%" border="0" cellpadding="0" cellspacing="2" class="pt9">
<form name="form" action="?action=savenew" method="post" onSubmit="return check();">
<tr>
<td width="100%" valign="top"><table width="86%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#00ccff" class="pt9">
<tr bgcolor="#FFFFFF">
<td width="18%" align="right" height="32">用户名:</td>
<td width="82%" height="32"><input name="Gsm1" type="text" class="input1" size="15" maxlength="11" >
<font color="#FF0000">*</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="26" align="right">序列号:</td>
<td><input name="GsmName1" type="text" class="input1" size="5" maxlength="5">
<font color="#FF0000">-</font><font color="#FF0000">
<input name="GsmName2" type="text" class="input1" size="5" maxlength="5">
-
<input name="GsmName3" type="text" class="input1" size="5" maxlength="5">
-
<input name="GsmName4" type="text" class="input1" size="5" maxlength="5">
*<br>
</font></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td colspan="2" class="note">资料</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="right">用户姓名:</td>
<td><input name="FirstName" type="text" class="input1" size="20"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="right">电话:</td>
<td><input name="Phone" type="text" class="input1" size="30" maxlength="18">
<input class="botton1" type="submit" onClick="return btnSubmit_onclick1()" name="Submit" value="确定">
<input class="botton1" type="reset" name="reset" value="重填"></td>
</tr>
</table></td>
</tr>
</form>
</table>
</BODY></HTML>
数据库驱动是Provider 你的代码如果去掉验证那块就是正常的 带了验证功能就出现http 500服务器错误。 下面这样改这个save.asp不出错但也没验证.期待高手的完美解决方案
<%
Set Rs1 = Server.CreateObject("Adodb.Recordset")
strSql = "Select * from tblSell where (id is null)"
Rs1.Open StrSql, Conn, 3, 3
Rs1.AddNew
Rs1("Gsm1") = Request("Gsm1")
Rs1("GsmName1") = Request("GsmName1")&Request("GsmName2")&Request("GsmName3")&Request("GsmName4")
Rs1("GsmPrice1") = Request("GsmPrice1")
Rs1("FirstName") = Request("FirstName")
Rs1("Phone") = Request("Phone")
Rs1("Address") = Request("Address")
Rs1("E-Mail") = Request("E-Mail")
Rs1("Description") = Request("Description")
Rs1.Update
Rs1.Close
Call OutScriptLoc("alert('您的资料已经成功提交.')","jszx2.asp")
Response.End
Rs.Close
%> 展开
<!-- #include file="common.asp" -->
</HEAD>
<%
If Request("action") = "savenew" Then
Set Rs1 = Server.CreateObject("Adodb.Recordset")
strSql = "Select * from tblSell where (id is null)"
Rs1.Open StrSql, Conn, 3, 3
Rs1.AddNew
Rs1("Gsm1") = Request("Gsm1")
Rs1("GsmName1") = Request("GsmName1")&Request("GsmName2")&Request("GsmName3")&Request("GsmName4")
Rs1("FirstName") = Request("FirstName")
Rs1("Phone") = Request("Phone")
Rs1.Update
Rs1.Close
Call OutScriptLoc("alert('您的资料已经成功提交.')","jszx.asp")
Response.End
End If
%>
<BODY topmargin=0 >
<table width="100%" border="0" cellpadding="0" cellspacing="2" class="pt9">
<form name="form" action="?action=savenew" method="post" onSubmit="return check();">
<tr>
<td width="100%" valign="top"><table width="86%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#00ccff" class="pt9">
<tr bgcolor="#FFFFFF">
<td width="18%" align="right" height="32">用户名:</td>
<td width="82%" height="32"><input name="Gsm1" type="text" class="input1" size="15" maxlength="11" >
<font color="#FF0000">*</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="26" align="right">序列号:</td>
<td><input name="GsmName1" type="text" class="input1" size="5" maxlength="5">
<font color="#FF0000">-</font><font color="#FF0000">
<input name="GsmName2" type="text" class="input1" size="5" maxlength="5">
-
<input name="GsmName3" type="text" class="input1" size="5" maxlength="5">
-
<input name="GsmName4" type="text" class="input1" size="5" maxlength="5">
*<br>
</font></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td colspan="2" class="note">资料</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="right">用户姓名:</td>
<td><input name="FirstName" type="text" class="input1" size="20"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="right">电话:</td>
<td><input name="Phone" type="text" class="input1" size="30" maxlength="18">
<input class="botton1" type="submit" onClick="return btnSubmit_onclick1()" name="Submit" value="确定">
<input class="botton1" type="reset" name="reset" value="重填"></td>
</tr>
</table></td>
</tr>
</form>
</table>
</BODY></HTML>
数据库驱动是Provider 你的代码如果去掉验证那块就是正常的 带了验证功能就出现http 500服务器错误。 下面这样改这个save.asp不出错但也没验证.期待高手的完美解决方案
<%
Set Rs1 = Server.CreateObject("Adodb.Recordset")
strSql = "Select * from tblSell where (id is null)"
Rs1.Open StrSql, Conn, 3, 3
Rs1.AddNew
Rs1("Gsm1") = Request("Gsm1")
Rs1("GsmName1") = Request("GsmName1")&Request("GsmName2")&Request("GsmName3")&Request("GsmName4")
Rs1("GsmPrice1") = Request("GsmPrice1")
Rs1("FirstName") = Request("FirstName")
Rs1("Phone") = Request("Phone")
Rs1("Address") = Request("Address")
Rs1("E-Mail") = Request("E-Mail")
Rs1("Description") = Request("Description")
Rs1.Update
Rs1.Close
Call OutScriptLoc("alert('您的资料已经成功提交.')","jszx2.asp")
Response.End
Rs.Close
%> 展开
展开全部
将save.asp改成如下试试:
你的代码没有问题啊,是不是你的数据库驱动用了driver?如果是建议用provider那次一个朋友也遇到过这个事情,代码没错,但是数据库驱动用driver就是无法做出来!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file "conn.asp" -->
<% Dim countname
countname=Request.Form("GsmName1")&Request.Form("GsmName2")&Request.Form("GsmName3")&Request.Form("GsmName4")
set rs2 = server.CreateObject("adodb.recordset")
sql2 = "select gsm from tblgsm where gsm ="&countname
rs2.open sql2,conn,1,1
if rs2.eof then
response.Write "<script>alert('对不起,该序列ID号不存在!');history.go(-1);</script>"
response.End()
else
Set Rs1 = Server.CreateObject("Adodb.Recordset")
Sql = "Select * from tblSell where (id is null)"
Rs1.Open Sql, Conn, 1, 3
Rs1.Addnew()
Rs1("Gsm1") = Request.Form("Gsm1")
Rs1("GsmName1") = countname
Rs1("FirstName") = Request.Form("FirstName")
Rs1("Phone") = Request.Form("Phone")
Rs1.Update
Rs1.Close
set Rs1 =nothing
rs2.close()
set rs2=nothing
End If
Call OutScriptLoc("alert('您的资料已经成功提交.')","jszx.asp")
Response.End
%>
你的代码没有问题啊,是不是你的数据库驱动用了driver?如果是建议用provider那次一个朋友也遇到过这个事情,代码没错,但是数据库驱动用driver就是无法做出来!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file "conn.asp" -->
<% Dim countname
countname=Request.Form("GsmName1")&Request.Form("GsmName2")&Request.Form("GsmName3")&Request.Form("GsmName4")
set rs2 = server.CreateObject("adodb.recordset")
sql2 = "select gsm from tblgsm where gsm ="&countname
rs2.open sql2,conn,1,1
if rs2.eof then
response.Write "<script>alert('对不起,该序列ID号不存在!');history.go(-1);</script>"
response.End()
else
Set Rs1 = Server.CreateObject("Adodb.Recordset")
Sql = "Select * from tblSell where (id is null)"
Rs1.Open Sql, Conn, 1, 3
Rs1.Addnew()
Rs1("Gsm1") = Request.Form("Gsm1")
Rs1("GsmName1") = countname
Rs1("FirstName") = Request.Form("FirstName")
Rs1("Phone") = Request.Form("Phone")
Rs1.Update
Rs1.Close
set Rs1 =nothing
rs2.close()
set rs2=nothing
End If
Call OutScriptLoc("alert('您的资料已经成功提交.')","jszx.asp")
Response.End
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询