View Full Version : Delete Selected
austin322
07-12-03, 10:27 AM
I have a list of records in the database on one of my pages. I have it setup, were you have to delete each record manually. I would like to add a checkbox beside the records, and a button to delete checked items, but when I set it up, when I checked some of the records the code I was using only delted the first record that I checked. Here is the code that I used:
<%
ScoreID=Request.QueryString("ScoreID")
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("Quiz.mdb")
rs = "DELETE * FROM Scores WHERE ScoreID= " & ScoreID & ";"
conn.execute rs
conn.close
set conn=nothing
%>
Please Help!
Originally posted by austin322
I have a list of records in the database on one of my pages. I have it setup, were you have to delete each record manually. I would like to add a checkbox beside the records, and a button to delete checked items, but when I set it up, when I checked some of the records the code I was using only delted the first record that I checked. Here is the code that I used:
Please Help!
No problem! :)
little sample script to display delete form
--------------------------------------
<%
response.write "<form method=post action=delete.asp>"
sql = "select id, name from scores order by id desc"
rs.open sql, conn,3,3
do while not rs.eof
response.write "<input type=checkbox name=score value=" & rs("id") & ">" & rs("name")
rs.movenext
loop
response.write "</form>"
%>
script to delete (delete.asp)
---------------------------------------
<%
sql="delete from scores where id in (" & request("score") & ")"
conn.Execute sql,,adCmdText + adExecuteNoRecords
%>
This works definitly with MSSQL and should also work with Access or mySQL. Test it.
Jenny
austin322
07-13-03, 08:29 AM
Thanks, I was using an Access database, and it worked. Now all I need is a "Check All" Checkbox.
Use JavaScript to activate all checkboxes...
Or put in an "if/then" statement before the SQL statement.
if request("clearall") then
sql="delete from scores"
else
sql="delete from scores where id in("&request("score")&")"
end if
Jenny
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.