I'm trying to access a Request.Form variable and plug it into an SQL statement, so that the statement will select just the particular data I need.
Here's the offending snippet of code:
I assumed that the problem was simply not having quotation marks in the right places, but I've tried many combinations of quotes, to no avail.
Here's the complete code (keep in mind that I'm still testing it, so it may not entirely make sense; first, I tried to get it to output something, now I'm at the point of trying to narrow down the output to just what I actually need).
AGAIN, please understand that this is still developmental code. Nothing is worse than getting back info on the rest of the program, when all I need (for this post anyway) is how to make that sql statement execute properly! :o) Help is greatly appreciated.
Here's the offending snippet of code:
Code:
sql = "SELECT DISTINCT name, extension FROM Employees WHERE name = " & Request.Form("name")
Here's the complete code (keep in mind that I'm still testing it, so it may not entirely make sense; first, I tried to get it to output something, now I'm at the point of trying to narrow down the output to just what I actually need).
Code:
<%@ LANGUAGE = "VBSCRIPT" %>
<% Option Explicit %>
<% If Request.Form("name") <> "" And Request.Form("extension") <> "" Then %>
<%
On Error Resume Next
Dim MyConnection, sql, rsRecords, results
sql = "SELECT DISTINCT name, extension FROM Employees WHERE name = " & Request.Form("name")
Set MyConnection = Server.CreateObject("ADODB.Connection")
Set rsRecords = Server.CreateObject("ADODB.RecordSet")
MyConnection.Open("employee")
rsRecords.Open sql, MyConnection
%>
<% If rsRecords.EOF Then %>
<H2> No records found </H2>
<%End If %>
<%
While Not rsRecords.EOF
results = rsRecords("name") & "  " & rsRecords("extension") & "<BR>"
Response.Write(results)
rsRecords.MoveNext
WEND
rsRecords.Close
MyConnection.Close
Set MyConnection = Nothing
%>
<%
Else
%>
<HTML>
<HEAD>
<TITLE>Database Connection</TITLE>
</HEAD>
<BODY onLoad = "document.searchDB.name.focus()">
<H3> Please Enter the Name and Extension You're Searching For: </H3>
<TABLE>
<FORM NAME = "searchDB" METHOD = "post" ACTION = "ASPDBtest.asp">
<TR><TD ALIGN = "left"><B>Name</B>
<TD><INPUT TEXT = "text" NAME = "name" SIZE = "25">
<TR><TD ALIGN = "left"><B>Extension</B>
<TD><INPUT TEXT = "text" NAME = "extension" SIZE = "25">
<TR><TD COLSPAN = "2" ALIGN = "left">
<TD><INPUT TYPE = "Submit" VALUE = "Submit">
<TD><INPUT TYPE = "Reset" VALUE = "Reset">
</FORM>
</TABLE>
</BODY>
</HTML>
<%End If%>
Comment