Print Page | Close Window

Trouble with variables in SQL query

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=2289
Printed Date: 29 March 2026 at 12:01pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Trouble with variables in SQL query
Posted By: spiderbaby
Subject: Trouble with variables in SQL query
Date Posted: 29 April 2003 at 10:33am

I've got 2 asp files - delemps.asp and deleteemps.asp.  delemps.asp lists all records in the 'emps' table of an Access database and provides a 'delete' hyperlink for each record.  This hyperlink calls the deleteemps.asp script, which asks the user to confirm the delete, and then processes the actual deletion of the record from the table.

The problem is with deleteemps.asp.  The variables passed to it by delemps.asp appear to be empty, thus causing my SQL query conditions to be false.  When I hard-code specific values into the query, the script works just fine.  Any ideas why the variables in the SQL query are empty?

The code for delemps.asp:

<%
Query = "SELECT last_name,first_name FROM emps ORDER BY last_name"
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open "phonedir"
Set RSlist = Server.CreateObject("ADODB.recordset")
RSlist.Open Query,DataConn,1,2
%>
<html>
<body bgcolor="lightblue" text="black" link="blue" vlink="blue">
<table border=1>
<tr><td><b>Last Name</b></td><td>First Name</td><td>&nbsp;</td></tr>
<%Do While Not RSlist.EOF
%>
<tr>
<td><%=RSlist("last_name")%></td>
<td><%=RSlist("first_name")%></td>
<td>
<a href="deleteemps.asp?first_name=<%=RSlist("first_name")%>&last_name=<%=RSlist("last_name")%>">delete</a>
</td>
</tr>
<%RSlist.Movenext
Loop%>
</table>
</body>
</html>

The code for deleteemps.asp:

<%
If Request("submit")="Yes" Then
   'delete record
   Query = "DELETE FROM emps WHERE last_name = '" & Request("last_name") & "' AND first_name = '" & Request("first_name") & "';"
   Set DataConn = Server.CreateObject("ADODB.Connection")
   DataConn.Open "phonedir"
   Set RSlist = Server.CreateObject("ADODB.recordset")
   RSlist.Open Query,DataConn,1,2
   Response.Redirect "delemps.asp"
ElseIf Request("submit")="No" Then
   'do not delete record
   Response.Redirect "delemps.asp"
Else
   'display option to delete%>
   <html>
   <body bgcolor="lightblue">
   Do you wish to delete: <B><%=Request("first_name")%>&nbsp;<%=Request("last_name")%></B>?
   <form action="deleteemps.asp">
   <input type="submit" name="submit" value="No">&nbsp;
   <input type="submit" name="submit" value="Yes">
   </form>
   </body>
   </html>
<%End If%>




Replies:
Posted By: MorningZ
Date Posted: 29 April 2003 at 10:42am

i'd change the thinking and keep it to one page..

for a quick and easy "confirmation", make the hyperlink to delete like so (i guarentee that the forum engine here will hork this up but here we go anyways)

<a href="thispage.asp?Del=<%= WhateverID %>" onClick="return confirm('OK to Delete?');">Delete</a>



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 29 April 2003 at 10:42am

whoa, it let that go  :-)

anyways, that'll allow you to stay on one page and you can put the delete logic on this one page and keep all the variables right here



-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net