Forums
This topic is locked
Passing a SQL string
Posted 07 Dec 2006 02:35:31
1
has voted
07 Dec 2006 02:35:31 Stephen Newbery posted:
HiI'm very new to dynamic pages and I've been trying to set up a search function that will search a range of prices. I was working from a Webthang.co.uk tutorial but just cannot get the thing to work. I have narrowed the problem down to my default.asp page passing the string (BETWEEN 1 AND 20000) to the results.asp page - well, at least I think I'm right!
All I want to happen is that when a selection is made from a price range drop-down box, the results will then be displayed on a new page. In aan attempt to work out the problem I'v ereduced the pages to bare bones. The code I have for the search page is:
<pre id=code><font face=courier size=2 id=code><form id="search1" name="search1" method="post" action="results.asp">
<table width="700" border="0" cellspacing="0" cellpadding="1">
<tr>
<td><select name="ysprice" id="ysprice">
<option value="1 AND 200000">Any</option>
<option value="1 AND 20000">£1 to £20000</option>
<option value="20000 AND 50000">£20000 to £50000</option>
<option value="50000 AND 200000">£50000 to £200000</option>
</select>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
The code from the results page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/yotshopODBC.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.Form("ysprice" <> "" Then
Recordset1__MMColParam = Request.Form("ysprice"
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command"
Recordset1_cmd.ActiveConnection = MM_yotshopODBC_STRING
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price BETWEEN ? ORDER BY price ASC"
Recordset1_cmd.Prepared = true
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 200, 1, 255, Recordset1__MMColParam) ' adVarChar
Set Recordset1 = Recordset1_cmd.Execute - Line 21
Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>Price: <%=(Recordset1.Fields.Item("price".Value)%></p>
<p>Construction: <%=(Recordset1.Fields.Item("construction".Value)%></p>
<p>Design: <%=(Recordset1.Fields.Item("design".Value)%></p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%></font id=code></pre id=code>
Everytime I preview it I get the following error:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Between operator without And in query expression 'price BETWEEN Pa_RaM000'.
/yot/results.asp, line 21
If someone can shed any light I would be most appreciative. I am tearing my hair out!!
Many thanks
Steve<font color=red></font id=red><b></b>
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
Replies
Replied 07 Dec 2006 13:24:30
07 Dec 2006 13:24:30 Lee Diggins replied:
Hi Stephen
A quick fix for this, amend this line:
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price BETWEEN ? ORDER BY price ASC"
to this:
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price BETWEEN " & Recordset1__MMColParam & " ORDER BY price ASC"
Comment out this line:
' Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 200, 1, 255, Recordset1__MMColParam) ' adVarChar
Let me know how you get on.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
A quick fix for this, amend this line:
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price BETWEEN ? ORDER BY price ASC"
to this:
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price BETWEEN " & Recordset1__MMColParam & " ORDER BY price ASC"
Comment out this line:
' Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 200, 1, 255, Recordset1__MMColParam) ' adVarChar
Let me know how you get on.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 07 Dec 2006 16:56:16
07 Dec 2006 16:56:16 Stephen Newbery replied:
Lee
This obviously proves what a newbie I am at this!!!
It worked like a dream - and while I still have some hair!
I do have one q that follows this though and that is; what happens if I want to add another list to be able to narrow the search down? I don't seem to be able to do it in Dreamweaver as it complains that the MMColParam is an invalid variable name.
Does that makes sense??
Thanks for your help so far, it really is much appreciated.
Steve
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
This obviously proves what a newbie I am at this!!!
It worked like a dream - and while I still have some hair!
I do have one q that follows this though and that is; what happens if I want to add another list to be able to narrow the search down? I don't seem to be able to do it in Dreamweaver as it complains that the MMColParam is an invalid variable name.
Does that makes sense??
Thanks for your help so far, it really is much appreciated.
Steve
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
Replied 07 Dec 2006 20:56:03
07 Dec 2006 20:56:03 Stephen Newbery replied:
Hmm, I may have jumped the gun a little!
Although the query works, it's not actually doing what I'm asking of it. The code you provided made sure it didn't get an error anymore but it's displying all of the records every time. If I try and put BETWEEN into the SQL or into the list box I'm preneted with an error!
It's something like this:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/yot/results.asp, line 17, column 77
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price " & BETWEEN Recordset1_MMColParam & " ORDER BY price ASC"
----------------------------------------------------------------------------^
Anything? Anyone?
Ta
Steve
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
Although the query works, it's not actually doing what I'm asking of it. The code you provided made sure it didn't get an error anymore but it's displying all of the records every time. If I try and put BETWEEN into the SQL or into the list box I'm preneted with an error!
It's something like this:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/yot/results.asp, line 17, column 77
Recordset1_cmd.CommandText = "SELECT * FROM YotStock WHERE price " & BETWEEN Recordset1_MMColParam & " ORDER BY price ASC"
----------------------------------------------------------------------------^
Anything? Anyone?
Ta
Steve
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
Replied 08 Dec 2006 00:03:52
08 Dec 2006 00:03:52 Stephen Newbery replied:
Okay, Okay, my bad!
I had inadvertantly opened DW8 instead of MX and it just doesn't work in that version - I guess something to do with SQL injection, I don't know I'm just guessing??
So it is actually working just fine!!
If anyone does know how I'd get it working in version 8 that would be good as I don't really want to use the student version of MX that I have.
THNX
Steve
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
I had inadvertantly opened DW8 instead of MX and it just doesn't work in that version - I guess something to do with SQL injection, I don't know I'm just guessing??
So it is actually working just fine!!
If anyone does know how I'd get it working in version 8 that would be good as I don't really want to use the student version of MX that I have.
THNX
Steve
------------------------------
DWMX | ASP | ACCESS
------------------------------
We will do what is right, of course - Tarzan, the animated series.
Replied 24 Jan 2007 01:22:23
24 Jan 2007 01:22:23 0 0 replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
If anyone does know how I'd get it working in version 8 that would be good as I don't really want to use the student version of MX that I have.
Steve
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Steve,
I noticed your post today.
I could do with some help on the same problem with Dreamweaver 8 (I'm working on the same tutorial). So if you found the solution for dreamweaver 8 I would appreciate it.
Thanks,
Mickey
If anyone does know how I'd get it working in version 8 that would be good as I don't really want to use the student version of MX that I have.
Steve
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Steve,
I noticed your post today.
I could do with some help on the same problem with Dreamweaver 8 (I'm working on the same tutorial). So if you found the solution for dreamweaver 8 I would appreciate it.
Thanks,
Mickey