Sometimes you need to delete a record without a form post. Here is a quick and dirty way of doing that. I am using Dreamweaver so the format is used is normal for Dreamweaver, but it can be applied easily any other way.
This has a url passed into a page called whatever you want, for example here i would have had a link that says :
<a href=”admin_branch_delete.asp?cc=<%=(rsCompanies.Fields.Item(“comp_branch_id”).Value)%>”>Delete Branch</a>
so the new page would be called admin_branch_delete.asp and would call the comp_branch_id value so the url of the next page could be something like this:
admin_branch_delete.asp?cc=1234
some the admin_branch_delete.asp page could have code like this:
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”65001″%>
<!–#include file=”Connections/conn_admin1.asp” –>
<%
Dim Conn
Dim SqlTemp
Dim sql_update
temp_id = request.QueryString(“cc”)
%>
<%
Set Conn = Server.CreateObject(“ADODB.Connection”)
Conn.connectionstring = MM_conn_admin1_STRING
Conn.Open
sql_update = “delete FROM comp_branch where comp_branch_id = ” & temp_id & “”
‘ Executing the sql update code
conn.Execute sql_update
‘ Done. Now Close the connection
conn.Close
Set conn = Nothing
%>
<% response.Redirect(“admin_contact_details.asp”) %>
The last line would just redirect you to the next page. Please note that this is deleting a record based on a autonumber field. If you want to delete via a word, which is quite scary, but still you would change this line.
sql_update = “delete FROM comp_branch where comp_branch_id = ” & temp_id & “”
to this
sql_update = “delete FROM comp_branch where comp_branch_id = ‘” & temp_id & “‘”
Hope that helps you.
