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> </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")%> <%=Request("last_name")%></B>?
<form action="deleteemps.asp">
<input type="submit" name="submit" value="No">
<input type="submit" name="submit" value="Yes">
</form>
</body>
</html>
<%End If%>