Hvad er der galt i nedenstående asp script?.
Scriptet gør det muligt at vise, rette og slette data fra en access
database. Scriptet virker fint mht. visning og sletning, men problemet
opstår når der skal rettes i de viste data.
Når scriptet kaldes vises en liste over data i databasen. Hver "række" data
findes frem vha. det unikke ID-nummer. Når der skal rettes kaldes data fra
"rækken" med de valgte ID-nummer frem. Første rettelse går fint og
rettelserne overskriver de eksisterende data i den "række".
Når den næste "række" (andet ID-nummer) data skal rettes opstår problemet.
I stedet for at de valgte data overskrives - vælger scriptet at overskrive
de data der blev kaldt første gang. Dvs. at den lægger rettelserne ind under
det forkerte id-nummer.
Håber det er til at forstå. Jeg har indsat scriptet herunder.
<%
If Session.Contents("AdminLevel") = "" Then
response.redirect("NP.asp")
end if
%>
<!--#include file ="SpawnedHead.asp"--><b>Mailing <%
response.write(request.querystring("action"))
dim lPage
if request.querystring("PageIndex") = "" then
lPage = 1
else
lPage = request.querystring("PageIndex")
end if
response.write("</b> (Page " & lPage & ")<br><br>")
mAction = request.querystring("action")
select case mAction
case "List"
call List()
case "Edit"
call Edit()
case "Delete"
call Delete()
end select
Function BuildNav (intPrev,IntNext,TotalPages)
Dim counter
BuildNav = BuildNav & "Page: "
counter = 1
do while counter <= TotalPages
if cint(counter) = cint(PageIndex) then
BuildNav = BuildNav & counter
Else
BuildNav = BuildNav & "<a href=MailingEdit.asp?action=List&PageIndex="
BuildNav = BuildNav & counter & ">" & Counter & "</a>"
End if
if cInt(counter) <> TotalPages then
BuildNav = BuildNav & " | "
end if
counter = counter + 1
Loop
BuildNav = BuildNav & "<br><br>"
end function
Function List()
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("SpawnedMailer.mdb"))
set rsMSign = Server.CreateObject("ADODB.recordset")
rsMSign.Open "SELECT * FROM MailingList order by DateAdded desc", conn, 3,
1, 1
Dim IntPageSize, PageIndex, TotalPages, TotalRecords
IntPageSize = 5
If request.querystring("PageIndex") = "" then
PageIndex = 1
else
PageIndex = request.querystring("PageIndex")
end If
rsMSign.PageSize = intPageSize
rsMSign.AbsolutePage = PageIndex
TotalPages = rsMSign.PageCount
dim intPrev, intNext
intPrev = PageIndex - 1
intNext = PageIndex + 1
response.write BuildNav (intPrev,IntNext,TotalPages)
response.write("Use the actions alongside your records.<br><br><br><table
cellspacing='0' cellpadding='0' border='0' align='center'
width='100%'><tr><td><i>Action</i></td><td><i>Mailing
ID</i></td><td><i>Email Addy</i></td><td><i>Date
Added</i></td></tr><tr><td><br></td></tr>")
If not rsMSign.EOF Then
Dim Count
Count = 1
do while NOT rsMSign.EOF AND Count <= IntPageSize
response.write("<tr><td><a href='MailingEdit.asp?Action=Edit&num=" &
rsMSign("MailingID") & "'>Edit</a> | <a
href='MailingEdit.asp?Action=Delete&num=" & rsMSign("MailingID") &
"'>Delete</a></td><td>" & rsMSign("MailingID") & "</td><td>" &
rsMSign("MailingAddy") & "</td><td>" & rsMSign("DateAdded") & "</td></tr>")
count = count + 1
rsMSign.MoveNext
Loop
Else
response.write("<tr><td colspan='4'><br><br><center><font
color='#FF0000'>There are no records currently to be
displayed.</font></center></td></tr>")
End if
response.write("</table>")
rsMSign.close
conn.close
end function
Function Edit()
Dim mID
mID = request.querystring("num")
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("SpawnedMailer.mdb"))
set rsMEdit = Server.CreateObject("ADODB.recordset")
If request.form.count = 0 then
rsMEdit.Open "SELECT * FROM MailingList Where MailingID =" & mID, conn
response.write("Edit the record:<br><br><br><form method='post'
action='MailingEdit.asp?Action=Edit&num=" & mID & "'>Mailing ID:<br><input
type='text' name='mailingid' readonly value='" & rsMEdit("MailingID") &
"'><br><br>Mailing Addy:<br><input type='text' name='mailingaddy' value='" &
rsMEdit("MailingAddy") & "'><br><br>Date Added:<br><input type='text'
name='dateadded' value='" & rsMEdit("DateAdded") & "'><br><br><input
type='submit' value='Edit!'></form>")
else
rsMEdit.Open "MailingList", conn, 2, 2
rsMEdit("MailingAddy") = Request.Form("mailingaddy")
rsMEdit("DateAdded") = Request.Form("dateadded")
rsMEdit.Update
response.write("The record has been updated. <a
href='MailingEdit.asp?action=List'>EDIT MORE</a>")
end if
rsMEdit.close
conn.close
end function
Function Delete()
Dim dID
dID = request.querystring("num")
dSQL = "DELETE * FROM MailingList WHERE MailingID =" & dID
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("SpawnedMailer.mdb"))
conn.Execute dSQL
conn.close
response.write("The record has been deleted. <a
href='MailingEdit.asp?action=List'>DELETE MORE</a>")
end function
response.write("<br><br><br><center><a href='AdminIndex.asp'>ADMIN
HOME</a><center>")
%><!--#include file ="SpawnedFoot.asp"-->
|