Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - deleting from a specific table
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

deleting from a specific table

 Post Reply Post Reply Page  12>
Author
mossmannen View Drop Down
Newbie
Newbie


Joined: 13 January 2004
Location: Sweden
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote mossmannen Quote  Post ReplyReply Direct Link To This Post Topic: deleting from a specific table
    Posted: 13 January 2004 at 4:11pm

Hi!

In my access db i have a couple of different tables.
I want to delete a specifc record from a specific table.
What I've done so far is:
A dropdown menu where I can choose the table and then click submit
Now, the records within that table is shown. So far so good.
What I want to do now is to be able to click on a record and it will be deleted. The problem is the script to delete the specific record from that table.
The code for the problem-script is:

<% 
Dim adoCon     
Dim rsDeleteEntry 
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"


Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

       strSQL="SELECT * FROM What goes here? WHERE ID=" & lngRecordNo
  
rsDeleteEntry.LockType = 3

rsDeleteEntry.Open strSQL, adoCon

rsDeleteEntry.Delete


rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing


Response.Redirect "../../index.asp"
%> 

I think the problem is in the Select * from ????
What goes after "from"?

What could I do?

 

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 4:15pm
You put the name of the table there...
Back to Top
mossmannen View Drop Down
Newbie
Newbie


Joined: 13 January 2004
Location: Sweden
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote mossmannen Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 5:05pm

Yeah...I know that....

But i selected the table from the dropdownmenu clicked submit, then all the records from the table selected is shown...but i don't know what to write after THIS "FROM". I have 6 different tables to choose from...

I post the whole code below:

The dropdown that let me select the table: (delete_link_form.asp)


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../style/style.css" rel="stylesheet" type="text/css">
</head>

<body>
 <form name="form" method="post" action="delete_link_select.asp">
   <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Category:</td>
      <td><select name="catgy">
          <option>MAin</option>
          <option>Music</option>
          <option>Pics</option>
          <option>Movie</option>
          <option>Otrher</option>
          <option>Admin</option>
        </select></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
     </table>
 </form>
</body>
</html>

The page listing the records from the table selected in the previous dropdown (delete_select.asp)

<% 
Dim adoCon     
Dim rsDeleteLink
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"
Set rsDeleteLink = Server.CreateObject("ADODB.Recordset")

     category = Request("catgy")
     select case category
      case "Main"
       strSQL="select * from Main"
      case "Music"
       strSQL="select * from Music"
      case "Pics"
       strSQL="select * from Pics"
      case "Movie"
       strSQL="select * from Movie"
      case "Other"
       strSQL="select * from Other"
      case "Admin"
       strSQL="select * from Admin"
     end select
     
rsDeleteLink.Open strSQL, adoCon

Do While not rsDeleteLink.EOF

     Response.Write ("<br>")
     Response.Write ("<a href=""delete_link.asp?ID=" & rsDeleteLink("ID") & """>")
     Response.Write (rsDeleteLink("Link_Text"))
     Response.Write ("</a>")
     Response.Write ("<br>")
     Response.Write (rsDeleteLink("Link"))
     Response.Write ("<br>")
  rsDeleteLink.MoveNext

Loop


rsDeleteLink.Close
Set rsDeleteLink = Nothing
Set adoCon = Nothing
%>

The code that should be executed when clicking on one of the listed records (delete_link.asp)


<%
Dim adoCon     
Dim rsDeleteEntry 
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"


Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

       strSQL="SELECT * FROM ????? WHERE ID=" & lngRecordNo
  
rsDeleteEntry.LockType = 3

rsDeleteEntry.Open strSQL, adoCon

rsDeleteEntry.Delete


rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing


Response.Redirect "../../index.asp"
%> 


So...what goes instead of the question marks? Or could this be solved easier?

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 5:35pm
Originally posted by mossmannen mossmannen wrote:

<% 
Dim adoCon     
Dim rsDeleteLink
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"
Set rsDeleteLink = Server.CreateObject("ADODB.Recordset")

     category = Request("catgy")
     select case category
      case "Main"
       strSQL="select * from Main"
      case "Music"
       strSQL="select * from Music"
      case "Pics"
       strSQL="select * from Pics"
      case "Movie"
       strSQL="select * from Movie"
      case "Other"
       strSQL="select * from Other"
      case "Admin"
       strSQL="select * from Admin"
     end select
     
rsDeleteLink.Open strSQL, adoCon

Do While not rsDeleteLink.EOF

     Response.Write ("<br>")
     Response.Write ("<a href=""delete_link.asp?ID=" & rsDeleteLink("ID") & "&cat=" & category & ">")
     Response.Write (rsDeleteLink("Link_Text"))
     Response.Write ("</a>")
     Response.Write ("<br>")
     Response.Write (rsDeleteLink("Link"))
     Response.Write ("<br>")
  rsDeleteLink.MoveNext

Loop


rsDeleteLink.Close
Set rsDeleteLink = Nothing
Set adoCon = Nothing
%>

The code that should be executed when clicking on one of the listed records (delete_link.asp)


<%
Dim adoCon     
Dim rsDeleteEntry 
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"

category = Request.QueryString("cat")
Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

       strSQL="SELECT * FROM " & category & " WHERE ID=" & lngRecordNo
  
rsDeleteEntry.LockType = 3

rsDeleteEntry.Open strSQL, adoCon

rsDeleteEntry.Delete


rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing


Response.Redirect "../../index.asp"
%> 


Be aware though that this is very unsecure, you should definately secure the script as otherwise everyone can put in a querystring and delete your records....



Edited by michael
Back to Top
mossmannen View Drop Down
Newbie
Newbie


Joined: 13 January 2004
Location: Sweden
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote mossmannen Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 6:35pm

Thanks alot.

I don't know how to secure the script. So this is good enough for me.

Back to Top
mossmannen View Drop Down
Newbie
Newbie


Joined: 13 January 2004
Location: Sweden
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote mossmannen Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2004 at 2:47pm

Tried it.

doesn't work. Error in FROM clause

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2004 at 3:01pm
Change
category = Request.QueryString("cat")
To
category = Request.Form("cat")
Because you are using the post verb not get...
Back to Top
mossmannen View Drop Down
Newbie
Newbie


Joined: 13 January 2004
Location: Sweden
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote mossmannen Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2004 at 3:08pm

sorry... that did not help

still the same problem



Edited by mossmannen
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.