PDA

View Full Version : Deleting Multiple Records Using Checkboxes


Jonathan
02-18-2006, 10:48 AM
Hi,

After two weekends trying to fathom it out and a 2.30am last night Iím now beside myself. Please help me!

I have produced a page used Deleting Multiple Records Using Checkboxes by Robís Boyle tutorial to delete records. http://www.webthang.co.uk/tuts/tuts_dmx/rob3/rob3.asp

Iím using Dreamweaver, Access 2000 and ASPVB

Iím using a master detail page sending a url parameter to the detail page. The detail page then deletes the information and reloads itself. The page brings up the information OK to delete. When I submit the page it deletes the records fine I wanted deleting but ignores the URL parameter and returns all information from the database table when reloading. This is the code that achieves it:

<%
If Request.Form("Process")="True" Then
'First check for a selection
If Request.Form("cSelect")="" Then
Response.Redirect("factor-quote-review.asp?")
End If

'Proceed with delete
Dim sDelete
sDelete = Replace(Request.Form, "&cSelect=", ",")
sDelete = Replace(sDelete, "cSelect=", "")
sDelete = Left(sDelete, Len(sDelete)-13)

set cDelete = Server.CreateObject("ADODB.Command")
cDelete.ActiveConnection = MM_Jonathan_STRING
cDelete.CommandText = "DELETE FROM tbl_bank_results WHERE tbl_bank_results.br_id IN (" & sDelete & ")"
cDelete.CommandType = 1
cDelete.CommandTimeout = 0
cDelete.Prepared = true
cDelete.Execute()
Response.Redirect("factor-quote-review.asp?")


End If
%>

Iíve identified that the page requires the parameters to filter my original recordset etc, there are none being passed through to it, e.g.

Response.Redirect("factor-quote-review.asp?param=something")

Problem is I canít identify successfully the code that fits the param=something.

Can you help?

Hers the page code:

<%@LANGUAGE="VBSCRIPT"%>
<%
' *** Logout the current user.
MM_Logout = CStr(Request.ServerVariables("URL")) & "?MM_Logoutnow=1"
If (CStr(Request("MM_Logoutnow")) = "1") Then
Session.Contents.Remove("MM_Username")
Session.Contents.Remove("MM_UserAuthorization")
MM_logoutRedirectPage = "login-ABL.asp"
' redirect with URL parameters (remove the "MM_Logoutnow" query param).
if (MM_logoutRedirectPage = "") Then MM_logoutRedirectPage = CStr(Request.ServerVariables("URL"))
If (InStr(1, UC_redirectPage, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_newQS = "?"
For Each Item In Request.QueryString
If (Item <> "MM_Logoutnow") Then
If (Len(MM_newQS) > 1) Then MM_newQS = MM_newQS & "&"
MM_newQS = MM_newQS & Item & "=" & Server.URLencode(Request.QueryString(Item))
End If
Next
if (Len(MM_newQS) > 1) Then MM_logoutRedirectPage = MM_logoutRedirectPage & MM_newQS
End If
Response.Redirect(MM_logoutRedirectPage)
End If
%>

<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="3"
MM_authFailedURL="Loginfail_able.htm"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
If Request.Form("Process")="True" Then
'First check for a selection
If Request.Form("cSelect")="" Then
Response.Redirect("factor-quote-review.asp?")
End If

'Proceed with delete
Dim sDelete
sDelete = Replace(Request.Form, "&cSelect=", ",")
sDelete = Replace(sDelete, "cSelect=", "")
sDelete = Left(sDelete, Len(sDelete)-13)

set cDelete = Server.CreateObject("ADODB.Command")
cDelete.ActiveConnection = MM_Jonathan_STRING
cDelete.CommandText = "DELETE FROM tbl_bank_results WHERE tbl_bank_results.br_id IN (" & sDelete & ")"
cDelete.CommandType = 1
cDelete.CommandTimeout = 0
cDelete.Prepared = true
cDelete.Execute()
Response.Redirect("factor-quote-review.asp?")


End If
%>
<%
Dim rsRecords__MMColParam
rsRecords__MMColParam = "1"
If (Request.QueryString("b_id") <> "") Then
rsRecords__MMColParam = Request.QueryString("b_id")
End If
%>
<%
Dim rsRecords
Dim rsRecords_numRows

Set rsRecords = Server.CreateObject("ADODB.Recordset")
rsRecords.ActiveConnection = MM_Jonathan_STRING
rsRecords.Source = "SELECT br_id, Date, cr_id, AllowClientToViewFactorsQuote, ProposedFacility FROM tbl_bank_results WHERE b_id = " + Replace(rsRecords__MMColParam, "'", "''") + " ORDER BY br_id DESC"
rsRecords.CursorType = 0
rsRecords.CursorLocation = 2
rsRecords.LockType = 1
rsRecords.Open()

rsRecords_numRows = 0
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Session("MM_username") <> "") Then
Recordset1__MMColParam = Session("MM_username")
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_Jonathan_STRING
Recordset1.Source = "SELECT Companyname, username FROM tbl_banks WHERE username = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsRecords_numRows = rsRecords_numRows + Repeat1__numRows
%>
<%
Dim MM_paramName
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>First Factor UK</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="First Factor UK Experts in Factoring and Invoice Finance broking solutions."/>
<meta name="keywords" content="First Factor UK, Firstfactoruk, Factoring Confidential Invoice Discounting, broker, business finance, asset based lending, chartered accountant, accountant, business adviser, broker, Introduce, Commission "/>
<meta name="language" content="en-gb"/>
<meta name="author" content="First Factor UK"/>
<meta name="copyright" content="2003 First Factor UK"/>
<meta name="robots" content="ALL"/>
<meta name="revisit-after" content="5 days"/>
<meta name="document-rights" content="Copyrighted Work"/>
<meta name="document-type" content="Public"/>
<meta name="document-rating" content="Safe for Kids"/>
<meta name="document-distribution" content="Global"/>
<meta http-equiv="Content-Language" content="EN-GB"/>
<meta name="Publisher" content="First Factor UK"/>
<meta name="MSSmartTagsPreventParsing" content="true"/>
<meta http-equiv="imagetoolbar" content="no"/>
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="stylesheet" type="text/css" href="style.css" media="print"/>
<meta http-equiv="Content-Style-Type" content="text/css"/>
<link href="style.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript">

var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase ())==-1)
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}

</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapimgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.osrc;i++) x.src=x.osrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.osrc) x.osrc=x.src; x.src=a[i+2];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
status=msgStr;
document.MM_returnValue = true;
}

function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>

<script type="text/javascript" language="JavaScript" src="with_flash/html/flash/flashobject.js"></script>

</head>
<body style="background-color:#FFFFFF" onload="MM_preloadImages('with_flash/html/images/m1r.jpg','with_flash/html/images/m2r.jpg','with_flash/html/images/m3r.jpg','with_flash/html/images/m4r.jpg','with_flash/html/images/m5r.jpg','with_flash/html/images/m6r.jpg');MM_callJS('goforit()')">

<script type="text/javascript" src="Backtotop/bak2top_strict.js"></script>
<table width="759" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="759" height="30" valign="top">
<div id="menu">

Please enable JavaScript in your browser to view this content. </div>
<script type="text/javascript">
// <![CDATA[

var fo = new FlashObject("with_flash/html/flash/menu-abl-1.swf", "flashcontent", "735", "80", 6, "#ffffff");
// this appears if user doesn't have the required Flash Player version
fo.altTxt = "Please upgrade to the latest version of Flash Player ('http://www.macromedia.com/go/getflashplayer/').";
fo.bypassTxt = "

Click here ('?detectflash=false&" + fo.sq + "') if you already have Flash Player " + fo.version + " installed.</p>";
fo.write("menu");

// ]]>
</script>
</td>
</tr>
<tr><td>with_flash/html/images/top_line.jpg</td></tr>
<tr><td width="759" height="208" valign="top">
<table width="753" border="0" cellpadding="0" cellspacing="0">
<tr><td>with_flash/html/images/spacer.gif</td>
<td width="496" height="208" valign="top">
<div id="header">

Please enable JavaScript in your browser to view this content. </div>
<script type="text/javascript">
// <![CDATA[

var fo = new FlashObject("with_flash/html/flash/ABL_area.swf", "flashcontent", "496", "210", 6, "#ffffff");
// this appears if user doesn't have the required Flash Player version
fo.altTxt = "Please upgrade to the latest version of Flash Player ('http://www.macromedia.com/go/getflashplayer/').";
fo.bypassTxt = "

Click here ('?detectflash=false&" + fo.sq + "') if you already have Flash Player " + fo.version + " installed.</p>";
fo.write("header");

// ]]>
</script></td>
<td style="background-image:url(with_flash/html/images/px.jpg)">with_flash/html/images/spacer.gif</td>
<td width="245" height="208" valign="top" style="padding-top:0px ">
<div style="margin-left:6px ">
<table>
<tr valign="middle">
<td height="47">with_flash/html/images/sym.jpg</td>
<td class="green"><%=(Recordset1.Fields.Item("username").Value)%> of <%=(Recordset1.Fields.Item("Companyname").Value)%></td>
</tr>
<tr valign="middle">
<td height="47">with_flash/html/images/sym.jpg</td>
<td class="green" title="Log out user"><div align="left"><a href="<%= MM_Logout %>" class="green" onmouseover="MM_displayStatusMsg('UK Market Leading Invoice Finance Brokers ');return document.MM_returnValue">Log
out user </a></div></td>
</tr>
<tr valign="middle">
<td height="47"><span class="green">with_flash/html/images/sym.jpg</span></td>
<td class="green"><script>


var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="am"
if (hours>=12)
dn="pm"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<medium><font color='#777B51' face='tahoma'>"+dayarray[day]+", "+daym+" "+montharray[month]+" "+year+" "+hours+":"+minutes+" "+dn+"</font></medium>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}

</script>
<span id="clock"></span></td>
</tr>
<tr valign="middle">
<td height="47"><span class="green">with_flash/html/images/sym.jpg</span></td>
<td class="green"><div align="left"><a href="Factor-Useful-links.asp" class="green" title="Useful links">Useful
links</a> </div></td>
</tr>
</table>
</div></td>
</tr>
</table>
</td>
</tr>
<tr><td>with_flash/html/images/line_c.jpg</td></tr>
<tr>
<td width="759" height="234" valign="top">
<table width="753" border="0" cellpadding="0" cellspacing="0">
<tr><td width="753">with_flash/html/images/spacer.gif</td></tr>
<tr>
<td height="245" valign="top">
<table width="753" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="background-image:url(with_flash/html/images/px.jpg);background-position:right; background-repeat:repeat-y ">with_flash/html/images/spacer.gif</td>
<td height="245" valign="top" style="padding-top:2px ">
<div style="margin-left:7px ">


with_flash/html/images/7txt2.jpg </p>


Home &gt; Review, amend or delete quote &gt;<br style="line-height:15px " />
</p>
</div>
<div class="gray" style="margin-left:12px; width:711px; line-height:13px; padding-top:12px">


<strong class="green">Review or amend existing quotes [/b]</p>


These are the quotes you have raised against each client
request number. Our Client will have access only to the
quotations you authorise to be viewed. You can retain quotations
on the system. <a href="factor.asp">To raise a new quotation
against a quotation go to originate new quotation</a>. </p>
<form name="frmSelect" method="post" action="factor-quote-review.asp" id="frmSelect">
<table width="723">
<tr>
<td height="14" colspan="6"><div align="center" class="green"></div></td>
</tr>
<tr class="green">
<td width="41"><div align="center" class="green">Delete</div></td>
<td width="124"><div align="left" class="green">Date</div></td>
<td width="87"><div align="center" class="green">Client
request No </div></td>
<td width="86"><div align="center" class="green">ABL quote no </div></td>
<td width="226" class="green">Service you are quoting</td>
<td width="119"><div align="center" class="green">View access granted </div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsRecords.EOF))
%>
<tr>
<td><div align="center">
<input name="cSelect" type="checkbox" id="cSelect" value="<%=(rsRecords.Fields.Item("br_id").Value)%>" />
</div></td>
<td><%=(rsRecords.Fields.Item("Date").Value)%></td>
<td><div align="center"><%=(rsRecords.Fields.Item("cr_id").Value)%></div></td>
<td><div align="center">"><%=(rsRecords.Fields.Item("br_id").Value)%> (factor-quote-a.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & )</div></td>
<td><%=(rsRecords.Fields.Item("ProposedFacility").Value)%></td>
<td><div align="center">
<input <%If (CStr((rsRecords.Fields.Item("AllowClientToViewFactorsQuote").Value)) = CStr("True")) Then Response.Write("checked") : Response.Write("")%> name="access" type="checkbox" disabled="true" id="access" value="<%=(rsRecords.Fields.Item("AllowClientToViewFactorsQuote").Value)%>" />
</div></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsRecords.MoveNext()
Wend
%>
<tr>
<td colspan="6"><div align="center"></div></td>
</tr>
<tr>
<td colspan="6"><div align="right"><span class="green">
<input name="" type="submit" style="width:50px; height:17px; font-family:tahoma; font-size:10px " title="Update" onclick="if (!confirm('Are you sure you wish to delete these files?')) return false;" value="Submit" />
<input type="hidden" name="Process" value="True">
</span></div></td>
</tr>
</table>


</form>

</div>
</td>
<td>with_flash/html/images/spacer.gif</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>with_flash/html/images/spacer.gif</td></tr>
</table>
</td>
</tr>
<tr>
<td width="759" height="83" valign="top">
<table width="759" >
<tr>
<td>with_flash/html/images/spacer.gif</td>
<td width="737" height="83" valign="top" style="background-image:url(with_flash/html/images/bot_px.jpg);padding-top:30px ">
<div align="center" class="copy">site map (Sitemap.asp) <font style="FONT-SIZE: 11px"><span class="green"></span></font>Copyright
2003-2005&copy; Saville Group (Harrogate) Limited. All rights reserved.<font style="FONT-SIZE: 11px"><span class="green"></span></font><font style="FONT-SIZE: 11px"><span class="green"></span></font> <font style="FONT-SIZE: 11px"><span class="green"></span></font> (Terms-and-Conditions.asp) <font style="FONT-SIZE: 11px"><span class="green"></span></font>T&amp;C's (Terms-and-Conditions.asp)</div>
</td>
<td>with_flash/html/images/spacer.gif</td>
</tr>
</table>
with_flash/html/images/valid-xhtml10.gif (http://validator.w3.org/)
</td>
</tr>

</table>


</body>
</html>
<%
rsRecords.Close()
Set rsRecords = Nothing
%>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

davidj
02-20-2006, 08:39 AM
sorry but you are using ASP which is a skill we are lacking

if you used PHP then that wouldnt be a problem