• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

Run SQL and pass value button in ASP

I have an ASP page which reads from a database, a list of records that i have put in there.

Example:
1] Test.User4
2] Joe.Smith
3] Daniel.Jones

On the page, it lists these users in a table, and displays an X icon next to each record in the table:

                 <%
While (NOT rsUsers.EOF)
%>
                  </span>
                  <table width="300" border="0" align="center" cellpadding="4" cellspacing="0" class="HFSVDottedBottom">
                    <tr>
                      <td width="80%" class="TextSmallBlackNonCaps"><% =rsUsers.Fields.Item("admin_user").Value %></td>
                      <td width="20%" align="center" class="TextSmallBlackNonCaps"><a href=""><img src="../Images/Cross.png" alt="Delete User <%=rsUsers.Fields.Item("admin_user").Value %>"width="15" height="15" border="0"/>
                       
                      </a></td>
                      <%  
                                      rsUsers.MoveNext
                                      Response.Flush()                                      
                                      wend %>

What i want, is when the person using the website clicks the cross icon, it passes the value on the row its on "Admin_User".value to a sql statement which then runs a delete command.

So like: DELETE FROM ADMIN_USERS WHERE ADMIN_USER = '" + THE RECORD ON THE ROW + "'"

How can i get it to pass the record, and run the statement as well?
0
AVONFRS
Asked:
AVONFRS
  • 2
1 Solution
 
DanielWillmottCommented:
You could create a separate ASP page that does the actual delete and then redirects back to the page above. Your hyperlink tag would then be as follows below.
Of course, it would be very important to make sure the user is being deleted as a result of someone using the page and not calling it directly with some keyed value or spoofed page. Maybe you already have security and you can check at the beginning of the page below to see of the user is authorized to do this function.

<a href='deleteuser.asp?user=<%=rsUsers.Fields.Item("admin_user").Value%>'>
 
pseudo code for deleteuser.asp:
 
<%
user=Response.QueryString("user")
 
if user<>"" then
' add code here to perform the delete statement on the database
SQL="DELETE FROM ADMIN_USERS WHERE ADMIN_USER = '" + user + "'"
'connect to database
'execute sql statement
end if
 
response.redirect("<asp page from above>")
%>

Open in new window

0
 
BadotzCommented:
<$.02>
Rather than actually deleting the row, I would create a 'status' field in every master table and change its value from [0] to  to [1]. Then you can filter "deleted" rows by excluding any rows with a status  of [1].

This costs nothing in the way of resources and has the added benefit of making you appear to be a god when you miraculously recover data the Poor User has accidentally deleted ;-)
</$.02>
0
 
AVONFRSAuthor Commented:
Thanks for your help. I have tried the response by DanielWillmott

Here is my code on the processor page - DeleteUserProcessor.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
      Dim delusername

      delusername = Response.QueryString("user")
      
      if delusername<>"" then
      
      Dim rsUsers_cmd
      
      Set rsUsers_cmd = Server.CreateObject("ADODB.Command")
      rsUsers_cmd.ActiveConnection = MM_HFSV_String
      rsUsers_cmd.CommandText = "DELETE FROM HFSVAdmins where admin_user = '" + delusername + "'"
      rsUsers_cmd.Prepared = true      
      rsUsers_cmd.Execute
      
      end if
      
      response.Redirect("/Administration.asp")
      %>

When i run this page though i get the following message:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Response.QueryString'

/DeleteUserProcessor.asp, line 5
0
 
AVONFRSAuthor Commented:
Not to worry.

Response.QueryString

Should have been Request.QueryString

All working now. Thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now