+ Reply to Thread
Results 1 to 4 of 4

Thread: Delete selected information from database from table

  1. #1
    Barn Newbie Arshan is an unknown quantity at this point Arshan's Avatar
    Join Date
    Jul 2009
    Posts
    9
    Rep Power
    3

    Delete selected information from database from table

    Hi,

    I have a small database that keeps track of time off request. I am using ASP for it. What I need to do is add a button or check box that allows a person to delete one of the requests.

    I could do this with a drop down menu, but that isn't user friendly enough. Is there a way to add a button or checkbox to each row that would allow the user to select a the info from that field in the table and delete it in the database?

    I know the code to delete entries, all I would need is the way to add a button/checkbox at each stage, and how to use it to identify the data to be deleted.

    Here is what I have to create the table and get the information:

    Code:
    <%@ Language=VBScript %>
    <%Option explicit
    Dim oRs, conn, connect, strSQL
    
    set conn=server.CreateObject ("adodb.connection")
    connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\data\users.mdb") & ";Persist Security Info=False"
    conn.Open connect %>
    
    
    <html>
    <head>
    	<script language="JavaScript" src="calendar_us.js"></script>
    	<script language="JavaScript" src="gen_validatorv31.js" type="text/javascript"></script>
    
    
    <title> PTO Reqeust Information </title>
    
    
    
    </head>
    <body>
    
    
    
    </form>
    
    <table width="100%" border="1" >
    
    <tr>
    
    <%
    
    dim mynumber
    mynumber = request.form("number")
    
    	Set oRs=Server.CreateObject("adodb.recordset")
    		strSQL = "SELECT * FROM Pto_TBL WHERE Number = '" & mynumber & "'"
            oRs.Open strSQL, conn
    
    
                  Response.Write  ("<td>") &("ID Number: ")  & ("<td>") &  ("Start Date: ") & ("<td>") & ("End Date: ") &  ("<td>") & ("Hours used: ")& ("<td>")
    		Do while not oRs.EOF
    
    			Response.Write  ("<td>")  & oRS("ID") & ("<td>") &  oRS("StartDate") & ("<td>")  & oRS("EndDate") &  ("<td>")  & oRS("hours") & ("<td>")
    	        Response.Write("<tr>")
    		    oRs.MoveNext
    
    
    	loop
    	%>
    
    
    </table>
    
    
    </body>
    </html>
    
    Number is from the previous page, that they enter. If there are any other questions let me know. Thanks for your help.

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Your HTML doesn't look at all well formatted. You are missing end tags from your <tr> and <td> tags. You have a closing </form> tag but no opening tag.

    The easiest way to do this with this layout is to just add a hyperlink that passes the ID to a page that runs the delete code and then redirects back to this page.
    Code:
     	Do while not oRs.EOF
    
    			Response.Write  ("<tr><td><a id=""link" & oRS("ID") & """ href=""deletePage.asp?ID=" & oRS("ID") & """>Delete</a></td><td>"  & oRS("ID") & "</td><td>" &  oRS("StartDate") & "</td><td>" & oRS("EndDate") &  "</td><td>"  & oRS("hours") & ("</td></tr>")
          oRs.MoveNext
    
    I've tried to tidy up the tags somewhat as well. Then on your delete page just retrieve the ID querystring and use that to delete the entry from the db.

    Hope that helps.

  3. #3
    Barn Newbie Arshan is an unknown quantity at this point Arshan's Avatar
    Join Date
    Jul 2009
    Posts
    9
    Rep Power
    3

    Quote Originally Posted by richyrich View Post
    Your HTML doesn't look at all well formatted. You are missing end tags from your <tr> and <td> tags. You have a closing </form> tag but no opening tag.

    The easiest way to do this with this layout is to just add a hyperlink that passes the ID to a page that runs the delete code and then redirects back to this page.
    Code:
     	Do while not oRs.EOF
    
    			Response.Write  ("<tr><td><a id=""link" & oRS("ID") & """ href=""deletePage.asp?ID=" & oRS("ID") & """>Delete</a></td><td>"  & oRS("ID") & "</td><td>" &  oRS("StartDate") & "</td><td>" & oRS("EndDate") &  "</td><td>"  & oRS("hours") & ("</td></tr>")
          oRs.MoveNext
    
    I've tried to tidy up the tags somewhat as well. Then on your delete page just retrieve the ID querystring and use that to delete the entry from the db.

    Hope that helps.

    Thank you, I'll give it a shot. I'm sure you can tell this is my second day with HTML and ASP. I was surprised I got that far.

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Ah...OK...In which case I'd probably redo your page to include the whole lot inside <form></form> elements and then use a seperate checkbox for each entry, giving each the same name, and a value of the ID.

    Add a button to submit the form and then use request.form("checkBoxName") which will give a comma seperated list of all the checkbox values that were ticked.

    Hope that makes sense.

+ Reply to Thread

Similar Threads

  1. Check box pop up information??
    By dtz in forum JavaScript Programming
    Replies: 4
    Last Post: May 1st, 2009, 08:21 AM
  2. Delete all records in table (syntax) then re-pop
    By Rebelle in forum SQL Development
    Replies: 11
    Last Post: March 10th, 2009, 11:43 AM
  3. Database table design
    By Ziggy in forum Database Design Help
    Replies: 17
    Last Post: February 16th, 2009, 01:55 PM
  4. Database accessbility information
    By ramez75 in forum Microsoft Access
    Replies: 7
    Last Post: January 12th, 2009, 09:52 PM
  5. Getting data from a selected row in a gridview
    By peebman2000 in forum .NET Development
    Replies: 3
    Last Post: July 31st, 2008, 01:18 PM

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

SEO by vBSEO