题
我和我的代码下面挣扎,我读了登录用户的用户名和试图插入他们的名字到一个SQL表称为许可证,该表包含2列1包含许可证号,另一个是在所有空此刻却一个用户名应沿着侧之一,当该页面加载插入。目前,该页面只是不断地循环,并没有被插入到表中。内部connection1.asp用户确实有读/写访问数据库。
任何想法?感谢
<%@LANGUAGE="VBSCRIPT" LCID=1033%>
<%
aName = Split(Request.ServerVariables("LOGON_USER"), "\")
user = aName(UBound(aName))
user = UCase(user)
Erase aName
%>
<!--#include file="Connections/connection1.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_connection1_STRING
Recordset1.Source = "SELECT * FROM Licenses2 WHERE userid = '" & user & "';"
Recordset1.Open()
%>
<HTML><HEAD></HEAD>
<BODY leftmargin="5" onLoad="setTimeout('reloadFunction()',500000)">
<% Do While NOT Recordset1.EOF %>
<% strUserName =(Recordset1.Fields.Item("userid").Value)%>
<% response.write strUserName %>'s Serial Number:
<% strSerial =(Recordset1.Fields.Item("serial").Value)%>
<% response.write strSerial %>
<% Recordset1.movenext %>
<% loop %>
<%
If strUserName = user then
'record found do nothing
'response.write "user found"
else
adoCon.Execute = "SET ROWCOUNT 1; UPDATE Licenses2 SET userid = '" & user & "' WHERE userid = 'NULL';"
Response.AddHeader "Refresh", "3"
End if
%>
</BODY>
</HTML>
<%
Recordset1.Close()
Set Recordset1 = Nothing
Set Recordset2 = Nothing
%>
解决方案
如果没有找到用户,你应该做的,而不是INSERT UPDATE的?
如果更新是正确的,改变过去的空...删除引号。现在您比较'NULL'
,而不是价值NULL
的一个字符串值,它应该是为空
SET ROWCOUNT 1; UPDATE Licenses2 SET userid = '" & user & "' WHERE userid IS NULL;
另外,看看你是否可以注释掉<BODY ... >
标签和创建无RELOADFUNCTION一个新的,看看是否有差别。
最后,阅读了关于SQL注入,因为你的代码很容易出现注入式攻击。在StackOverflow.com搜索SQL注入,你会发现很多的解释,范例和治疗。
其他提示
检查是否LOGON_USER真的返回任何数据。如果您有IIS安全性设置为“匿名”的访问,那么这将不与任何填充。
您的代码也将潜在地易于SQL注入攻击。
不隶属于 StackOverflow