---
title: "The else from hell!"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/10752-the-else-from-hell/page2"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Hallgren"
published: "2001-07-20T14:41:00.000Z"
updated: "2001-07-24T13:25:00.000Z"
replies: 29
views: 295
page: 2
pages: 2
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/10752-the-else-from-hell"
---

# The else from hell!

_Sida 2 av 2._

## #21 — LarsG, 2001-07-23T13:04Z

Mm, men det verkar vara ett end if för mycket i din kod.

```
<%
if lcase(request.Form("uid")) ="admin" And lcase(request.Form("pws")) = "admin" Then
response.redirect("admin.asp")
end if

set dbcon = Server.CreateObject("ADODB.Connection")
dbcon.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.Mappath("restauranger.mdb")
if RequestCookies("lunchguiden")("uid") = "" Or RequestCookies("lunchguiden")("pwd") = "" then
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & request.Form("uid") & "' And rest_pwd = '" & request.Form("pwd") & "'")
if UID.EOF then
%>Felaktigt lösenord<br><br><a href="inloggning.asp">Försök igen</a><%
ResponseCookies("lunchguiden")("uid") = ""
ResponseCookies("lunchguiden")("pwd") = ""
ResponseCookies("lunchguiden").Expires = Date + 365
else
Session("login_id") = UID("rest_id")
Response.Redirect("meny.asp")
if Request.Form("spara_losenord") = "ja" then
ResponseCookies("lunchguiden")("uid") = UID("rest_uid")
ResponseCookies("lunchguiden")("pwd") = UID("rest_pwd")
ResponseCookies("lunchguiden").Expires = Date + 365
end if
'[b]
' detta följande end if borde bort 
' tycker jag det ser ut som
' end if
'[/b]
else
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & RequestCookies("lunchguiden")("uid") & "' And rest_pwd = '" & RequestCookies("lunchguiden")("pwd") & "'")
if UID.EOF then
%>Felaktigt lösenord<br><br><a href="login.asp">Försök igen</a><%
ResponseCookies("lunchguiden")("uid") = ""
ResponseCookies("lunchguiden")("pwd") = ""
ResponseCookies("lunchguiden").Expires = Date + 365
else
Session("login_id") = UID("rest_id")
Response.Redirect("meny.asp")
end if
end if

%>
```

Permalänk: https://www.webforum.nu/p/278562

## #22 — Hallgren, 2001-07-23T13:07Z

Det ska väl in ett **else** mellan 

```
<%
if lcase(request.Form("uid")) ="admin" And lcase(request.Form("pws")) = "admin" Then
response.redirect("admin.asp")
end if
```

och

```
set dbcon = Server.CreateObject("ADODB.Connection")
dbcon.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.Mappath("restauranger.mdb")
if RequestCookies("lunchguiden")("uid") = "" Or RequestCookies("lunchguiden")("pwd") = "" then
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & request.Form("uid") & "' And rest_pwd = '" & request.Form("pwd") & "'")
if UID.EOF then
```

etc.

Permalänk: https://www.webforum.nu/p/278563

## #23 — LarsG, 2001-07-23T13:16Z

Nej det behövs inte då du gör response.redirect inuti if

Permalänk: https://www.webforum.nu/p/278564

## #24 — @nders, 2001-07-23T13:18Z

nu när det bara är en redirect som skall utföras, så kan vi förenkla till detta:

```
if lcase(request.Form("uid")) ="admin" And lcase(request.Form("pws")) = "admin" Then response.redirect("admin.asp")
```

bara en liten parentes... :)

Permalänk: https://www.webforum.nu/p/278565

## #25 — Hallgren, 2001-07-23T13:35Z

Får "Expected Statment line 22 End If"

```
<%
if lcase(request.Form("uid")) ="admin" And lcase(request.Form("pws")) = "admin" Then response.redirect("admin.asp")
end if
set dbcon = Server.CreateObject("ADODB.Connection")
dbcon.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.Mappath("restauranger.mdb")
if RequestCookies("lunchguiden")("uid") = "" Or RequestCookies("lunchguiden")("pwd") = "" then
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & request.Form("uid") & "' And rest_pwd = '" & request.Form("pwd") & "'")
if UID.EOF then
%>Felaktigt lösenord<br><br><a href="inloggning.asp">Försök igen</a><%
ResponseCookies("lunchguiden")("uid") = ""
ResponseCookies("lunchguiden")("pwd") = ""
ResponseCookies("lunchguiden").Expires = Date + 365
else
Session("login_id") = UID("rest_id")
Response.Redirect("meny.asp")
if Request.Form("spara_losenord") = "ja" then
ResponseCookies("lunchguiden")("uid") = UID("rest_uid")
ResponseCookies("lunchguiden")("pwd") = UID("rest_pwd")
ResponseCookies("lunchguiden").Expires = Date + 365
end if

else
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & RequestCookies("lunchguiden")("uid") & "' And rest_pwd = '" & RequestCookies("lunchguiden")("pwd") & "'")
if UID.EOF then
%>Felaktigt lösenord<br><br><a href="login.asp">Försök igen</a><%
ResponseCookies("lunchguiden")("uid") = ""
ResponseCookies("lunchguiden")("pwd") = ""
ResponseCookies("lunchguiden").Expires = Date + 365
else
Session("login_id") = UID("rest_id")
Response.Redirect("meny.asp")
end if
end if

%>
```

Permalänk: https://www.webforum.nu/p/278566

## #26 — LarsG, 2001-07-23T14:36Z

Ursäkta mig, men mitt inlägg om att det var ett end if för mycket var helt fel.

```
<%
if lcase(request.Form("uid")) ="admin" And lcase(request.Form("pws")) = "admin" Then 
response.redirect("admin.asp")
end if
set dbcon = Server.CreateObject("ADODB.Connection")
dbcon.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.Mappath("restauranger.mdb")
if RequestCookies("lunchguiden")("uid") = "" Or RequestCookies("lunchguiden")("pwd") = "" then
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & request.Form("uid") & "' And rest_pwd = '" & request.Form("pwd") & "'")
if UID.EOF then
%>Felaktigt lösenord<br><br><a href="inloggning.asp">Försök igen</a><%
ResponseCookies("lunchguiden")("uid") = ""
ResponseCookies("lunchguiden")("pwd") = ""
ResponseCookies("lunchguiden").Expires = Date + 365
else
Session("login_id") = UID("rest_id")
Response.Redirect("meny.asp")
if Request.Form("spara_losenord") = "ja" then
ResponseCookies("lunchguiden")("uid") = UID("rest_uid")
ResponseCookies("lunchguiden")("pwd") = UID("rest_pwd")
ResponseCookies("lunchguiden").Expires = Date + 365
end if
end if
else
set UID = dbcon.execute("SELECT * FROM rest WHERE rest_uid = '" & RequestCookies("lunchguiden")("uid") & "' And rest_pwd = '" & RequestCookies("lunchguiden")("pwd") & "'")
if UID.EOF then
%>Felaktigt lösenord<br><br><a href="login.asp">Försök igen</a><%
ResponseCookies("lunchguiden")("uid") = ""
ResponseCookies("lunchguiden")("pwd") = ""
ResponseCookies("lunchguiden").Expires = Date + 365
else
Session("login_id") = UID("rest_id")
Response.Redirect("meny.asp")
end if
end if

%>
```

VB-script är känsligt för radbrytningar. Om man skriver så här på en rad

```
if a = b then c = 12
```

så skall det inte vara något end if efter.

Permalänk: https://www.webforum.nu/p/278567

## #27 — Hallgren, 2001-07-23T14:56Z

Nu blir jag ledsen. Det funkar ändå inte. Det är precis som om det inte läser av "admin". :(

Dags att åka hem snart. Lite skönt ialla fall. :)

Permalänk: https://www.webforum.nu/p/278568

## #28 — @nders, 2001-07-24T06:25Z

om du inte fått det att lira, så släng upp hela koden och rapportera felmeddelanden.

du vet att man inte får ge upp, eller hur ? :)

Permalänk: https://www.webforum.nu/p/278569

## #29 — Hallgren, 2001-07-24T12:52Z

Den koden jag kör med är dem som LarsG la in sist. Har dock fixat ResponseCookies.

Permalänk: https://www.webforum.nu/p/278570

## #30 — Hallgren, 2001-07-24T13:25Z

Ok, nu så tänkte jag skylla först på LarsG då jag fått fel kod, sen tänkte jag skylla på @nders för han inte märkte det tidigare MEN jag har bestämt mig för att skylla på mig själv och de som vill får gärna "sparka" lite på mig.

**DET SKALL VARA PWD OCH INTE PWS!!**

Tack för mig. :)

PS. Tack @nders! DS.

Permalänk: https://www.webforum.nu/p/278571

---

Tråden på webben: https://www.webforum.nu/amne/asp/10752-the-else-from-hell/page2  
Föregående sida: https://www.webforum.nu/amne/asp/10752-the-else-from-hell.md
