Vad är fel i: Din kod ser ut (ungefär) så här Det är bättre att ange användarnamn och lösenord som vilkor i SQL satsen istället för at loopa igenom hela deltagare:Loop
<%
If Request.QueryString("logga")="in" Then
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "driver{Microsoft Access Driver (*.mdb)};dbq"& Server.MapPath("db/db.mdb") &";"
Set RecSet = Server.CreateObject("ADODB.Recordset")
Addera = "SELECT * FROM deltagare"
RecSet.Open Addera, Connect, adOpenStatic, adLockOptimistic
Do Until RecSet.EOF
If Request.Form("username123")=RecSet("alias") And Request.Form("password123")=RecSet("password") Then
RecSet.MoveNext
Loop
RecSet.Close
Set RecSet = Nothing
Set RecSet2 = Server.CreateObject("ADODB.Recordset")
Addera="SELECT * FROM deltagare WHERE alias = '"& Request.Form("username123") &"'"
RecSet2.Open Addera, Connect, adOpenStatic, adLockOptimistic
%>
bla bla bla
<%
Else
RecSet.MoveNext
Loop
RecSet.Close
Set RecSet = Nothing
End If
RecSet2.Close
Set RecSet2 = Nothing
End If
%>
Fel meddelande:
'loop' without 'do'
/konfa2002/deltagare.asp, line 65
LoopSv: Loop
<code>
do until
if ... then
loop
end if
</code>
Do until och loop hänger ihop så du måste dom på samma nivå
<code>
do until
if ... then
...
end if
loop
</code>
Att hämta alla poster och jämföra dom i VB-skript är väldigt ineffektivt. Sätt villkor i din select-sats istället
<code>
<%
If Request.QueryString("logga")="in" Then
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "driver{Microsoft Access Driver (*.mdb)};dbq"& Server.MapPath("db/db.mdb") &";"
username = "'" & replace(request.form("username123","'","''") & "'"
password = "'" & replace(request.form("password123","'","''") & "'"
query = "select * from deltagare where alias = " & username & " and [password] = " & password
Set RecSet = connect.execute(query)
if Recset.eof then
'användaren finns ej
else
'användaren finns
end if
recset.close
connect.close
end if
%>
</code>Sv: Loop
<code>
<%
Function SQLText(Value)
If Len(Value) > 0 Then
SQLText = "'" & Replace(Value, "'", "''") & "'"
Else
SQLText = "Null"
End If
End Function
If Request.QueryString("logga") = "in" Then
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "driver{Microsoft Access Driver (*.mdb)};dbq"& Server.MapPath("db/db.mdb") &";"
Set RecSet = Server.CreateObject("ADODB.Recordset")
Addera = "SELECT * FROM deltagare WHERE alias = " & SQLText(Request.Form("username123")) & " AND password = " & SQLText(Request.Form("password123"))
RecSet.Open Addera, Connect
If RecSet.EOF Then
Response.Write "<H3>Felaktigt användarnamn eller lösenord!</H3>"
Else
Response.Write "<H3>Välkommen: " & RecSet("alias") & "</H3>"
'Osv....
'...
End If
RecSet.Close
Set RecSet = Nothing
End If
%>
</code>