Hej alle,
Jeg er stødt ind i et problem med et script der står for at tilføje artikler
til en access database og vise en oversigt for brugeren. Browseren kan ikke
hente siden, men står bare og loader uendeligt uden at komme med en
fejlmeddelelse. Jeg har givet fulde rettigheder til både script-filen og
databasen, og der burde ikke være noget antivirus eller lignende der
blokerer, så det lugter lidt af en uendelig løkke et sted. Jeg kører IIS 5.1
på Win XP professional.
Håber der er nogle der kan gennemskue hvad der er galt - koden er som
følger:
<%
on error resume next
u_action=request.querystring("u_action")
u_title=replace(trim(request.form("u_title")),"'","'")
u_body=replace(trim(request.form("u_body")),"'","'")
u_author=replace(trim(request.form("u_author")),"'","'")
id=request.querystring("id")
script_name=request.servervariables("script_name")
%>
<%
if u_action <> "add" then
select case u_action
case "insert"
sql = "insert into features (title,body,author)"
sql = sql & " values( '" & u_title & "' , '" & u_body & "' , '" &
u_author & "' )"
case "display"
sql="select * from features where id = "&id
case else
sql="select * from features order by date desc "
end select
accessdb="features"
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, cn
if u_action <> "insert" then
if rs.eof then
response.redirect script_name
end if
end if
'Start html output
%>
<html>
<title>Recent Articles</title>
<body bgcolor="#FFFFFF">
<% 'Display successful addition of article to db
if u_action="insert" then %>
Your Article was added.<br>
<% else
'Display db output %>
<% do while not rs.eof and counter < 6
' Change 6 to any number of Titles you want to display
counter=counter+1 %>
<% if u_action <> "display" then %>
<a href="<%= script_name %>?u_action=display&id=<%= rs("id")%>"><%=
rs("title") %></a> <%= FormatDateTime(rs("date"), vbShortDate) %><br>
<% else %>
<b><%= rs("title") %></b><br>
by <%= rs("author") %>
<p>
<pre>
<%= rs("body") %>
</pre>
<% end if %>
<%
rs.movenext
loop %>
<% end if
end if
%>
<% if u_action="add" then
'if the user is adding a new article
'then display the form input fields %>
<script Language="JavaScript">
<!--
function Blank_TextField_Validator(form)
{
if (form.u_title.value == "")
{
alert("Please fill in the title field.");
form.u_title.focus();
return (false);
}
if (form.u_body.value == "")
{
alert("Please fill in the body field.");
form.u_body.focus();
return (false);
}
if (form.u_author.value == "")
{
alert("Please fill in the author field.");
form.u_author.focus();
return (false);
}
return (true);
}
//-->
</script>
<form method="post" action="<%= script_name %>?u_action=insert"
onsubmit="return Blank_TextField_Validator(this)">
Title<br>
<input type="text" name="u_title" size="45"><p>
Body<br>
<textarea rows="8" name="u_body" cols="55"></textarea><p>
Author<br>
<input type="text" name="u_author" size="45"><p>
<input type="submit" value="Submit">
</form>
<% else
'if the user is doing anything other than adding an article
'display navigational hyperlinks %>
<p><a href="<%= script_name %>">View Recent Articles</a><br>
<a href="<%= script_name %>?u_action=add">Add Your Article</a>
<% end if %>
|