Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Trouble with variables in SQL query
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Trouble with variables in SQL query

 Post Reply Post Reply
Author
spiderbaby View Drop Down
Newbie
Newbie
Avatar

Joined: 29 April 2003
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote spiderbaby Quote  Post ReplyReply Direct Link To This Post Topic: Trouble with variables in SQL query
    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%>

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

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

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.