Link to home
Start Free TrialLog in
Avatar of AVONFRS
AVONFRS

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of DanielWillmott
DanielWillmott
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<$.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>
Avatar of AVONFRS
AVONFRS

ASKER

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
Avatar of AVONFRS

ASKER

Not to worry.

Response.QueryString

Should have been Request.QueryString

All working now. Thanks