Results 1 to 2 of 2

Thread: delete single record from database

  1. #1
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default delete single record from database

    is it possible to have a action button with a query string init..

    i have a basket page..which is linked to a database..
    to add stuff i have a """""<a href="basket.asp?ID=01001&Model=Sony KDL42V3000&price=999.99&quntaity=1"><img src="images/buy.gif" border=0 style="float: right" /></a> </a>""""" in my database and that passes a query string to the basket page which adds the new product in the basket..

    i want to make a delete button which will appear in the basket next to every item added and when thy click that button the product will be deleted..

    whats the best ways to do that..

  2. #2
    Join Date
    Dec 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Use this code:

    Code:
    <%
    	'Declare variables first!
    	Dim Conn, rs, SQl, msg
    	'Create Connection and RecordSet Objects
    	Set Conn = Server.CreateObject("ADODB.Connection")
    	Set rs = Server.CreateObject("ADODB.RecordSet")
    	'Open Connection And RecordSet Objects...
    	Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("## DATABASE PATH HERE!!! ##")
    	If (Request.Form("strAction") <> "" AND Request.Form("strID") <> "") Then
    		Conn.Execute("DELETE FROM Basket WHERE ID=" & Replace(Request.Form("strID"),"'","''"))
    		msg = "<div style=""font-family:verdana;color:red;clear:both;font-size:11px;"">Item deleted!</div>"
    	End If
    	SQl = "SELECT * FROM Basket"
    	rs.Open SQl, Conn, 1
    %>
    <script language="javascript" type="text/javascript">
    <!--
    function deleteItem(itemId)
    {
    	var theForm;
    	theForm = document.forms["fm"];
    	if (!theForm) {
    		theForm = document.fm;
    	}
    	if (confirm("Are you sure you want to delete this item?")) {
    		theForm.strAction.value = "delete";
    		theForm.strID.value = itemId;
    		theForm.submit();
    	}
    }
    //-->
    </script>
    <form name="fm" action='<%= Request.ServerVariables("Script_Name") & "?" & Request.QueryString %>' method="post" style="font-family:verdana;font-size:11px;">
    <input type="hidden" name="strAction" value="" />
    <input type="hidden" name="strID" value="" />
    	<table width="100%" border="1" style="font-family:verdana;font-size:11px;">
    		<tr>
    			<td width="55">ID</td>
    			<td width="650">Brand and Model</td>
    			<td width="20">Price</td>
    			<td width="60">Options</td>
    		</tr>
    		<%
    			Dim strId
    			While Not rs.EOF
    				strId = rs("ID")
    		%>
    		<tr>
    			<td width="55"><%= rs("ID") %></td>
    			<td width="193"><%= rs("Brand") %></td>
    			<td><%= rs("Price") %></td>
    			<td width="60"><input type="button" style="font-family:verdana;font-size:11px;" value="Delete" onclick="deleteItem('<%= strId %>')" /></td>
    		</tr>
    		<%
    				rs.MoveNext
    			WEnd
    		%>
    	</table>
    	<%= msg %>
    </form>
    <%
    	rs.Close
    	Conn.Close
    	Set rs = Nothing
    	Set Conn = Nothing
    %>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •