select case strAction case "write" ' vis formular til indtastning ShowOptions ShowForm case "show" ' vis indhold ShowOptions ShowList request ("fromid") case "insert" ' indsæt resultat af formular WriteForm ShowOptions ShowList 0 case else ' vis valgmuligheder ShowOptions end select
sub ShowForm ' viser en formular, hvor den besøgende skal indtaste i. %> <form action="guestbook.asp?action=insert" method="post"> Navn : <input type="text" name="guestname"><br> Email : <input type="text" name="guestemail"><br> <textarea name="guestmessage"> </textarea><br> <input type="submit" value="Indsend"> <% end sub
sub ShowList (intFromID) ' viser indlæg i gæstebogen. ' 10 indlæg vises ad gangen. dim strSQL, objRS, strWhere dim arrROws, i if intFromID > 0 then strWhere = " WHERE guestid <= " & intFromID & " " else strWhere = "" end if strSQL = "SELECT guestid, guestname, " & _ "guestemail, guestmessage FROM GuestBOOK " & _ strWhere & _ "ORDER BY datesubmitted DESC"
set objRS = server.createobject("ADODB.Recordset") with objRS .open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText if not .EOF then arrRows = .GetRows(10) end if .close end with set objRS = Nothing
if isArray(arrRows) then intFromID = arrRows(0,ubound(arrRows,2)) for i = 0 to ubound(arrRows,2) response.write arrRows(0,i) & ". " & _ arrRows(1,i) & _ "<br>" & arrRows(2,i) & _ "<br>" & arrRows(3,i) & "<hr>" next response.write _ "<a href='guestbook.asp?action=show&fromid=" & intFromID+10 & "'>Tilbage</a> " & _ "<a href='guestbook.asp?action=show&fromid=" & intFromID - 1 & "'>Frem</a>" else response.write "<p>Ikke flere indlæg i Gæstebogen.</p>" end if end sub
set objCMD = server.createobject("ADODB.Command") wtih objCMD .ActiveConnection = strConnect .CommandType = adCmdText .CommandText = strSQL .Execute end with set objCMD = Nothing end sub
sub ShowOptions 'Viser, hvilke muligheder der er. %> <h1>Gæstebog</h1> <p>Hej, du kan skrive i min gæstebog, hvis du har lyst. <br> <a href="guestbook.asp?action=write">Skriv i gæstebogen</a><br> <a href="guestbook.asp?action=show">Se hvad andre har skrevet</a> </p> <% end sub
%> </body></html>
Siden vil simpelthen ikke vises i browseren. Hvad kan der være galt ?
Hmm...Det går ikke altid som præsten prædikener Jeg har fået ændre nogle fejl, men der støder nye til Nu ASP-Filen sådan ud :
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="forbindelse.asp" --> <html><head><title>Gæstebog</title></head> <body bgcolor="#FFFFCC"> <% dim strAction
strAction=request ("action")
select case strAction case "write" ' vis formular til indtastning ShowOptions ShowForm case "show" ' vis indhold ShowOptions ShowList request ("fromid") case "insert" ' indsæt resultat af formular WriteForm ShowOptions ShowList 0 case else ' vis valgmuligheder ShowOptions end select
sub ShowForm ' viser en formular, hvor den besøgende skal indtaste i. %> <form action="guestbook.asp?action=insert" method="post"> Navn : <input type="text" name="guestname"><br> Email : <input type="text" name="guestemail"><br> <textarea name="guestmessage"> </textarea><br> <input type="submit" value="Indsend"> <% end sub
sub ShowList (intFromID) ' viser indlæg i gæstebogen. ' 10 indlæg vises ad gangen. dim strSQL, objRS, strWhere dim arrROws, i if intFromID > 0 then strWhere = " WHERE guestid <= " & intFromID & " " else strWhere = "" end if strSQL = "SELECT guestid, guestname, " & _ "guestemail, guestmessage FROM GuestBook " & _ strWhere & _ "ORDER BY datesubmitted DESC"
set objRS = server.createobject("ADODB.Recordset") with objRS .open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText if not .EOF then arrRows = .GetRows(10) end if .close end with set objRS = Nothing
if isArray(arrRows) then intFromID = arrRows(0,ubound(arrRows,2)) for i = 0 to ubound(arrRows,2) response.write arrRows(0,i) & ". " & _ arrRows(1,i) & _ "<br>" & arrRows(2,i) & _ "<br>" & arrRows(3,i) & "<hr>" next response.write _ "<a href='guestbook.asp?action=show&fromid=" & intFromID+10 & "'>Tilbage</a> " & _ "<a href='guestbook.asp?action=show&fromid=" & intFromID - 1 & "'>Frem</a>" else response.write "<p>Ikke flere indlæg i Gæstebogen.</p>" end if end sub
set objCMD = server.createobject("ADODB.Command") with objCMD .ActiveConnection = strConnect .CommandType = adCmdText .CommandText = strSQL .Execute end with set objCMD = Nothing end sub
sub ShowOptions 'Viser, hvilke muligheder der er. %> <h1>Gæstebog</h1> <p>Hej, du kan skrive i min gæstebog, hvis du har lyst. <br> <a href="guestbook.asp?action=write">Skriv i gæstebogen</a><br> <a href="guestbook.asp?action=show">Se hvad andre har skrevet</a> </p> <% end sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.