Click to See Complete Forum and Search --> : cannot delete from checkbox select trougth database record
kalosneri
06-19-2005, 11:09 PM
i have 2 checkbox with the same name.
i use loop text.
and 1 "delete" button.
this is my checkbox:-
<input name="checkbox" type="checkbox" id="<%=delete1&p%>" value="<%=delete1&p%>" >
<input name="checkbox" type="checkbox" id="<%=delete1&p%>" value="<%=delete1&p%>" >
this is my "delete" button :-
<input name="delete" type="submit" id="delete" value="Delete" onclick="ondelete()">
when i click "delete" button an go o this fucntion:-
function ondelete(){
if (confirm("This will delete the links! Are you sure you want to do this!?"))
document.forms[0].action="Delete2.asp";
document.forms[0].submit();
}
this function going to this page:-
<!--#include file="Connections/stock_conn.asp" -->
<%
Dim strDeleteList
strDeleteList = Request.Form("checkbox")
If strDeleteList = "" Then
'No items to delete
Response.Write "You did not select any items to delete!"
Else
set Command1 = Server.CreateObject("ADODB.Command")
Command1.ActiveConnection = MM_stock_conn_STRING
Command1.CommandText = "DELETE FROM assembly WHERE s_code IN (" & strDeleteList & ") "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
set Command1 = Nothing
'Display to the user that the product have been deleted.
Response.Write Request.Form("checkbox").Count & " Record(s) were deleted..."
Response.Write "One moment, you will be redirected back"
End If
%>
i still cannot delete the item in the data base.
plis show me the correct cording to use for delete the record from data base?
simflex
06-20-2005, 10:32 PM
You needed a way to split the values that you are storing into your form variable = request("checkbox")
So, to make your life easier, then just use the replace function to split the values:
strDeleteList = Replace( strDeleteList, ", ", "','" )
Put above code just below this your code:
strDeleteList = Request.Form("checkbox")
and it should work.
kalosneri
06-20-2005, 11:49 PM
i do what u say but get error at..
Command1.Execute()
buntine
06-21-2005, 01:56 AM
Won't they be numeric values? If so, you cannot wrap them in single quotes.
Print your original SQL query out and see what you get:
Response.Write("DELETE FROM assembly WHERE s_code IN (" & strDeleteList & ") ")
Response.End
Place that before .Execute
Regards.
kalosneri
06-21-2005, 02:25 AM
the result:-
DELETE FROM assembly WHERE s_code IN (checkbox1','checkbox2','checkbox3)
i got the name of checkbox to delete but the checkbox is null cannot get any value from the selected item that i want to delete.
buntine
06-21-2005, 03:15 AM
Thats weird. The value of each checked checkbox is supposed to be passed to the server. What is the output HTML of the page that contains the form (before you submit it)?
Regards.
Vackhus
06-21-2005, 08:19 AM
Try this:
The_Values=request.form("formname")
for i=1 to len(The_Values)
if mid(The_Values,i,1)=", " then
k=k+1
end if
next
Vals=split(The_Values,", ")
for i=1 to k
<---Your SQL here and your WHERE must have value Vals(i-1)--->
next
simflex
06-21-2005, 08:31 AM
if they are numeric values, then the solution is very simple:
strDeleteList = Replace( strDeleteList, ", ", "," )
Copy above and replace the one I gave you earlier.
Buntine, if you had taken a closer look at the result he printed out for you, you would have seen the problem:
the result:-
DELETE FROM assembly WHERE s_code IN (checkbox1','checkbox2','checkbox3)
It should work now for him.
buntine
06-21-2005, 02:00 PM
But look what you have done. Aren't you just parsing the initial string and removing spaces? Why would that help? Why not just use the string as it comes in from the client?
Try this:
The_Values=request.form("formname")
for i=1 to len(The_Values)
if mid(The_Values,i,1)=", " then
k=k+1
end if
next
Vals=split(The_Values,", ")
for i=1 to k
<---Your SQL here and your WHERE must have value Vals(i-1)--->
next
The split function actually returns an array, so it could be:
The_Values = Request.Form("formname")
Vals = Split(The_Values, ", ")
For i = 0 To UBound(Vals) - 1
<---Your SQL here and your WHERE must have value Vals(i)--->
Next
Regards.
kalosneri
06-21-2005, 10:51 PM
sorry i so confuse...for ur information i'm have little knowledge about ASP.
i need ur help to solve my problem if u have time to try solve my problem.
i give u my cording:-
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/stock_conn.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<title>Master Code</title>
<!--******************** CLEAR CACHE MEMORY FOR THE PAGE****************************** -->
<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Prastocka" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
%>
<%
maincode = request.form("maincode")
%>
<script language="javascript">
// *********************************************************************************
function insert() {
var maincode=document.getElementById("maincode").value;
if (maincode != "") {
document.forms[0].action="addassembly.asp";
document.forms[0].submit();
}
}
//******************************FUNCTION VALIDATION QUANTITY*****************************
function FuncQty(p){
var qty=document.getElementById("txtqty"+p+"");
if (qty.value !="" ){
b=qty.value.search(/\D/);
for (i=0; i<4; i++){
if (b==i){
alert("Please Enter Integer");
qty.value = "";
}
}
}
}
//******************************FUNCTION VALIDATION QUANTITYNEXT*****************************
function FuncQtynext(p){
var Nqty=document.getElementById("newqty"+p+"");
if (Nqty.value !="" ){
a=Nqty.value.search(/\D/);
for (i=0; i<4; i++){
if (a==i){
alert("Please Enter Integer");
Nqty.value = "";
}
}
}
}
function GoSubmit(){
var maincode=document.getElementById("maincode").value;
if ( maincode != "" ) {
document.forms[0].action="assembly.asp";
document.forms[0].submit();
}
}
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
//CLEAR DATA GRID FIELD BY ONCLICK CLEAR.GIF
function clr(p){
var a1=document.getElementById("txts_code"+p+"");
var a2=document.getElementById("txtdesp"+p+"");
var a3=document.getElementById("txtqty"+p+"");
var a4=document.getElementById("txtuom"+p+"");
a1.value = "";
a2.value = "";
a3.value = "";
a4.value = "";
}
function clrNew(p){
var a1=document.getElementById("news_code"+p+"");
var a2=document.getElementById("newdesp"+p+"");
var a3=document.getElementById("newqty"+p+"");
var a4=document.getElementById("newuom"+p+"");
a1.value = "";
a2.value = "";
a3.value = "";
a4.value = "";
}
#########DELETE###########
function ondelete(){
if (confirm("This will delete the record! Are you sure you want to do this!?"))
document.forms[0].action="Delete2.asp";
document.forms[0].submit();
}
</script>
<%
dim conH
dim rsH
dim strSQLH
set conH=server.CreateObject("ADODB.Connection")
set rsH=server.CreateObject("ADODB.Recordset")
conH.open "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=stock"
strSQLH="SELECT * FROM assembly where maincode = '"& maincode &"'"
rsH.open strSQLH, conH
do while rsH.eof = false
maincode = rsH("maincode")
rsH.moveNext
loop
%>
<BODY bgcolor="white" text="black" link="#8000FF" vlink="gray" alink="teal" background="images/color.gif">
<form name="assembly" method="post">
<table width="66%" height="60" border=1 align=center borderColor="#d4d0c8" id="table5">
<tr>
<td height="54">
<table width="604" height="50" border="0" align="center" cellSpacing="0" id="table6">
<tr>
<td width="106" height="24">Master Code</td>
<td width="14">:</td>
<td width="173"><input name="maincode" type="text" id="maincode" tabindex="1" value ="<%=maincode%>" maxlength="15" onBlur="GoSubmit()">
</td>
<td width="119"> </td>
<td width="182"> </td>
</tr>
<tr>
<td height="26"> </td>
<td> </td>
<td> </td>
<td> </td>
<td><div align="right">
<input type="submit" name="Submit" value="Submit" onClick="insert();">
<input name="delete" type="submit" id="delete" value="Delete" onclick="ondelete()">
</div></td>
</tr>
</table>
</td>
</tr>
</table>
<div id="Layer1" style="position:absolute; width:659px; height:308px; z-index:1; top: 99px; overflow: auto; left: 170px;">
<TABLE width="73%" height="77" border=1 align=center cellPadding=1 cellSpacing=1 borderColor=#d4d0c8 >
<TR vAlign=top align=middle>
<th width="47">Delete</th>
<th width="132">Stock Code</th>
<th width="108">Description</th>
<th width="108">UOM</th>
<th width="63">Quantity</th>
<th width="40">Clear</th>
</tr>
<!-- *********************************************************************************** -->
<%
' table got record
dim conF
dim rsF
dim strSQLF
set conF=server.CreateObject("ADODB.Connection")
set rsF=server.CreateObject("ADODB.Recordset")
conF.open "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=stock"
strSQLF="SELECT * FROM assembly where maincode = '"& maincode &"'"
rsF.open strSQLF, conF
p = 0
x = 0
a = 9
txts_code = "txts_code"
txtdesp = "txtdesp"
txtuom ="txtuom"
txtqty = "txtqty"
checkbox = "checkbox"
for zIndex = 0 to a
do while rsF.eof = false
p = p+1
x = x + 1
s_code = rsF("s_code")
desp = rsF("desp")
uom= rsF("uom")
qty = rsF("qty")
%>
<TR vAlign=top>
<TD> <div align="center">
<input name="checkbox" type="checkbox" id="<%=checkbox&p%>" value="<%=checkbox&p%>" >
</div></TD>
<TD> <div align="center">
<input type="text" name="<%=txts_code&p%>" id ="<%=txts_code&p%>" value ="<%=s_code%>" size="22" tabindex="2">
</div></td>
<TD><div align="center">
<input type="text" name="<%=txtdesp&p%>" id = "<%=txtdesp&p%>" value="<%=desp%>" size="18" />
</div></TD>
<TD><div align="center">
<input name="<%=txtuom&p%>" type="text" id="<%=txtuom&p%>" value ="<%=uom%>" size="18" />
</div></TD>
<TD><div align="center">
<input type="text" name ="<%=txtqty&p%>" id="<%=txtqty&p%>" value ="<%=qty%>" size="10" onBlur="FuncQty('<%=p%>');" />
</div></TD>
<TD> <div align="center"><img src="file:///C|/Inetpub/wwwroot/gm/clear.gif" width="18" height="18" border="0" name="<%=txtclear&p%>" onClick="clr('<%=p%>');">
</div></td>
<%
rsF.moveNext
loop
next
p = 0
b = 9 - x
for iIndex = 0 to b
p = p+1
news_code = "news_code"
newdesp = "newdesp"
newuom ="newuom"
newqty = "newqty"
checkbox = "checkbox"
%>
<TR vAlign=top>
<TD><div align="center"> <div align="center">
<input name="checkbox" type="checkbox" id="<%=checkbox&p%>" value="<%=checkbox&p%>" >
</div>
<TD> <div align="center">
<input type="text" name="<%=news_code&p%>"id ="<%=news_code&p%>" value ="<%=Request.Form("news_code&p")%>" size="22">
</div></TD>
<TD><div align="center">
<input type="text" name="<%=newdesp&p%>" id = "<%=newdesp&p%>" value="<%=Request.Form("newdesp&p")%>" size="18" >
</div></TD>
<TD><div align="center">
<input type="text" name="<%=newuom&p%>" id="<%=newuom&p%>" value ="<%=Request.Form("newuom&p")%>" size="18" >
</div></TD>
<TD><div align="center">
<input type="text" name ="<%=newqty&p%>" id="<%=newqty&p%>" value ="<%=Request.Form("newqty&p")%>" size="10" onblur="FuncQtynext('<%=p%>');">
</div></TD>
<TD><div align="center"><img src="clear.gif" width="18" height="18" border="0" name="<%=newclear&p%>" onClick="clrNew('<%=p%>');"></option>
</div></td>
<%
next
%>
</TR>
</TABLE>
<div align="center"> </div>
</div>
</form>
</body>
</html>
simflex
06-22-2005, 01:43 PM
But look what you have done. Aren't you just parsing the initial string and removing spaces? Why would that help?
Actually, I wasn't criticizing you. I was really giving you credit by saying that sometimes it is really harder to see smaller problems than it is to see bigger problems. I was able to pick that because I have dealt with similar issues many times.
Having said that, the last solution, yes, removes spaces but still a good solution. It will solve his problem.
As a matter of fact, I took another look at his original question and realized that the replace function wasn't really necessary at all.
That should have worked for him, just as mine should have worked for him. If none of those worked, then there is some other issues with his code but unfortunately, I don't have the time to wad through a ton of the code he posted.
I can only provide 10 minute simpler solutions right now, not because I don't want to help but I can only afford very little to assist, unfortunately.