注册 登录
编程论坛 ASP技术论坛

[求助]代码怎么错了

威龙嘉少 发布于 2007-10-22 18:41, 404 次点击

<%
Function GetValidateCode()
Randomize Timer '产生一个随机树
GetValidateCode=Left(Int(Rnd*9998)+1000,4)
If Len(GetValidateCode)>4 Then
GetValidateCode=Len(GetValidateCode&9999,4)
End If
End Function
%>
<!--#include file="lj_conn.asp"-->
<%
if request.QueryString("action")="add" then
l_url=trim(request.Form("url"))
l_url=replace(l_url,"'","")
l_font=trim(request.Form("name"))
l_font=replace(l_font,"'","")
l_logo=trim(request.Form("adress"))
l_logo=replace(l_logo,"'","")
l_alt=trim(request.Form("demo"))
l_alt=replace(l_alt,"'","")
key=trim(request.Form("key"))
key=replace(key,"'","")
if l_url <> "" and l_font <> "" and l_logo <> "" and l_alt <> "" and ValidateCode=key then
conn.execute "insert into lianjie(l_url,l_font,l_logo,l_alt) values('"&l_url&"','"&l_font&"','"&l_logo&"','"&l_alt&"')"
response.Write("<script language='javascript'>alert('联结已经成功注册,请等待审核!');histotry.go(-1);</script>")
else
if l_url="" then
msg=msg&"地址不能为空!"
elseif l_font="" then
msg=msg&"网站名称不能为空!"
elseif l_logo="" then
msg=msg&"图片不能为空!"
elseif l_alt="" then
msg=msg&"备注不能为空!"
elseif request.Form("key") <> ValidateCode then
msg=msg&"验证码错误!"
end if
response.Write("<script language='javascript'>alert(信息没有填写完整!);histotry.go(-1);</script>")
end if
end if
%>
</head>

<body>
<form id="form1" name="form1" method="post" action="lj_add.asp?action=add">
<div align="center">
<table width="524" height="202" border="1">
<tr>
<td width="154">网站名称:</td>
<td width="354"><label>
<input name="name" type="text" id="name" />
</label></td>
</tr>
<tr>
<td>联结地址:</td>
<td><label>
<input name="url" type="text" id="url" />
</label></td>
</tr>
<tr>
<td>图片地址:</td>
<td><label>
<input name="adress" type="text" id="adress" />
</label></td>
</tr>
<tr>
<td>站点说明:</td>
<td><label>
<input name="demo" type="text" id="demo" />
</label></td>
</tr>
<tr>
<td>验证 码:</td>
<td><label>
<%ValidateCode=GetValidateCode()'将获取的验证码赋值给ValidateCode%>
<input type="hidden" name="ValidateCode" value="<%=ValidateCode%>">
<input name="key" type="text" class="input3" id="key" size="5" maxlength="4">
<%=ValidateCode%>
</label></td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
<td><label>
<input type="reset" name="Submit2" value="重置" />
</label></td>
</tr>
</table>
</div>
</form>
就这代码,我都不知道怎么错了,郁闷,看不出有什么错误啊,可是注册值为空的时候,根本就没有弹出错误提示对话框,但是插入的时候可以正常操作,奇怪了!

4 回复
#2
dushui2652007-10-22 18:51
这一段代码:if l_url="" then
msg=msg&"地址不能为空!"
elseif l_font="" then
msg=msg&"网站名称不能为空!"
elseif l_logo="" then
msg=msg&"图片不能为空!"
elseif l_alt="" then
msg=msg&"备注不能为空!"
elseif request.Form("key") <> ValidateCode then
msg=msg&"验证码错误!"

修改为:

if l_url="" then
msg=msg&"地址不能为空!"
if l_font="" then
msg=msg&"网站名称不能为空!"
if l_logo="" then
msg=msg&"图片不能为空!"
if l_alt="" then
msg=msg&"备注不能为空!"
if request.Form("key") <> ValidateCode then
msg=msg&"验证码错误!"

试试看!
#3
yms1232007-10-22 18:57
if l_url="" then
msg=msg&"地址不能为空!"
elseif l_font="" then
msg=msg&"网站名称不能为空!"
elseif l_logo="" then
msg=msg&"图片不能为空!"
elseif l_alt="" then
msg=msg&"备注不能为空!"
elseif request.Form("key") <> ValidateCode then
msg=msg&"验证码错误!"
end if
response.Write("<script language='javascript'>alert(信息没有填写完整!);histotry.go(-1);</script>")
end if
改为
Dim ReFalse
ReFalse=True
IF l_url="" Then
msg=msg&"地址不能为空!"
ReFalse=False
End IF
IF ReFalse and l_font="" Then
msg=msg&"网站名称不能为空!"
ReFalse=False
End IF
IF ReFalse and l_logo="" Then
msg=msg&"图片不能为空!"
ReFalse=False
End IF
IF ReFalse and l_alt="" Then
msg=msg&"备注不能为空!"
ReFalse=False
End IF
IF request.Form("key") <> ValidateCode and ReFalse Then
msg=msg&"验证码错误!"
ReFalse=False
End IF
Response.Write("<script language='javascript'>alert(信息没有填写完整!);histotry.go(-1);</script>")
#4
tianyu1232007-10-22 19:15

response.Write("<script language='javascript'>alert(信息没有填写完整!);histotry.go(-1);</script>")

改为:

response.Write("<script language='javascript'>alert('信息没有填写完整!');histotry.go(-1);</script>")

你定义了变量msg,但却没有引用!

最好把上面那句改为下面:

response.Write("<script language='javascript'>alert('"& msg &"');histotry.go(-1);</script>")

这样就能实现你想要的功能!
#5
威龙嘉少2007-10-22 19:42

谢谢各位了,不过那个随机验证码好像没有什么用啊,这是怎么会师啊,空这也不错误提示,这是我从网上下的,怎么会师啊,谁有带图片的验证码程序啊?

1