Click to See Complete Forum and Search --> : Passing Data in ASP
gowans007
06-01-2004, 12:17 PM
I have a page which displays data I have in a table
However I want to put a link that says delete after each record and when its click it will delete that record
my table name is: TABLENAME
The fields are: Name, Team, Number, Comments, Type
the data is in a SQL db and I have used the code on a seperate page (DELETE FROM TABLENAME) which clears the hole table.
How can I do this,
Also some problems I have encountered it shows an error if people use a , or ? in the comments code.
It does'nt pick up any new lines when displaying the data
and my form I use to enter data has no checks to make sure these fields are all entered so imprtant fields can be left blank.
If anyone can solve those problems it would be great also.
Thanks!!!
Bhanu
06-01-2004, 01:26 PM
hi,
u can solve this by popup through javascript.
send recordid to javascript function. delete that id on popup page.
write sql as "delete from table where recordid = " Request.QueryString("id")
==========================
< link onclick="deleteRec(<%=rs.recordid%>)">Delete
<Script language="JavaScript" >
function deleteRec(Rid){
popurl = "delete.asp?id=" + Rid;
window.open(popurl,null,"height=100,width=100,left=1500,top=1500;status=no,toolbar=no,menubar=no,location=no,scrollbars=no");
this.close();
}
</script>
this window will not be visible as left out of screen.
Bhanu
buntine
06-01-2004, 08:14 PM
I would not recommend the use of JavaScript.
You will need to use a WHERE clause to prevent SQL from clearing every record in the table.
DELETE * FROM tablename WHERE id = " & CInt(Request.QueryString("id"))
Regards.
gowans007
06-02-2004, 08:23 AM
Hi I am going to use a Get method and put the details in the Delete link and then go to another page which will pick up this info and then insert in into the Delete where command for SQL right?????
I have tryed for the link
& ("<a href=del_sst.asp?Comments=") & rs("Comments") & ("&Type=") & rs("Type") & (">Delete</a></align>") etc...
but the link only holds the data upto the first space.
however the comments has a number of words in it for each record how do i do this.
Haven't even though about how I get the data for the delete command.
Can someone code this out for me or show me a exaple of code as I am being Dense here.
Thankyou
Bhanu
06-02-2004, 11:32 AM
If you have spaces in comments your string will fail
need to encode and decode html string
Bhanu
gowans007
06-02-2004, 12:26 PM
Thanks but how do I do that?
Any tips of example code would be very helpfull.
As the comments code is really the key field as if it matches that it should delete that record.
Thanks Again Guys!
Bhanu
06-02-2004, 12:56 PM
try this link
http://www.w3schools.com/html/html_ref_urlencode.asp
you can get encodeing decoding of URL
regards
Bhanu
Bhanu
06-02-2004, 12:59 PM
Try this from MSDN Lib
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/seconscriptencodersyntax.asp
Bhanu
Bhanu
06-02-2004, 01:05 PM
Try this from MSDN Lib
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/seconscriptencodersyntax.asp
Bhanu