Forums

This topic is locked

sql query error

Posted 14 Dec 2005 16:29:01
1
has voted
14 Dec 2005 16:29:01 sofie sof posted:
Hello,
I am building a family tree.
The visitors can fill in their name and first name in a form.
With these 2 elements i want to write a sql query so that the database gives me the people with that name and/or first name.In dreamweaver i created this code, but i get an error saying that the sql statement should be closed...

This is the code :
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_conn_baertfamily_STRING
Recordset1.Source = "SELECT * FROM tb_foto WHERE naam='Request.Form("familienaam"' and voornaam='Request.Form("voornaam"'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<b></b>

Could someone help me out here please.

Tx ,
Pete<b></b>

Replies

Replied 28 Dec 2005 09:13:25
28 Dec 2005 09:13:25 Tjerk Heringa replied:
Hi,

i am not sure about the single quotes in your code.
And the select statement absolutely needs a closing semicolon (<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

----------------------------------------------
The client is allways right even if he is not.
Replied 26 Jan 2006 10:57:12
26 Jan 2006 10:57:12 Paul Plant replied:
Hi Pete,

When you get the error about the sql statement not being closed, it is referring to the fact that you've mixed up quotes and double quotes and therefore it cannot process the statement. (Although you need a semi-colon to signal 'end of statement' in most SQL operations using command-line type tools, you don't need it here so don't worry.)

Try changing your code as follow:

Recordset1.Source = "SELECT * FROM tb_foto WHERE naam='" + Request.Form("familienaam" + "' OR voornaam='" + Request.Form("voornaam" + "'"

Good luck!

Reply to this topic