Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to CF. Trouble w/ parameters.

Status
Not open for further replies.

itsecsol

Programmer
Dec 31, 2001
9
0
0
US
I am etting this message:

Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)


[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'question_id ='.



The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (10:1) to (10:61).


Date/Time: 12/31/01 12:53:21
Browser: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)
Remote Address: 127.0.0.1
HTTP Referer: Query String: question_id=
 
expression 'question_id ='. Get rid of the first single quote prior to question DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Are you passing a value? Do you have a value? Output the variable before you run the query and see if you have a value.
 
There is a database called quiz.mdb with a table called questions with the fields:
question_id
question
correct_answer
answer1
answer2
answer3
answer4



This is the code from the home.cfm file

<!DOCTYPE html public &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<cfif not isdefined(&quot;question_id&quot;)>
<cfquery name=&quot;get_count&quot; datasource=&quot;quiz&quot; dbtype=&quot;odbc&quot;>
select count(question_id) as total_questions
from questions
</cfquery>
</cfif>

<CFQUERY NAME=&quot;get_question&quot; DATASOURCE=&quot;quiz&quot; DBTYPE=&quot;odbc&quot;>
SELECT question_id,
question,
answer1,
answer2,
answer3,
answer4
FROM questions
WHERE question_id = <CFIF ISDEFINED(&quot;question_id&quot;)>
#question_id#
<CFELSE>
#RandRange(1, get_count.total_questions)#
</CFIF>
</CFQUERY>

<HTML>
<HEAD>
<TITLE>My Home Page</TITLE>
</HEAD>
<BODY bgcolor=&quot;#ffffff&quot;>
<DIV align=&quot;center&quot;>
<HR><B>Welcome to My Home Page!</B>
<HR><B>Today's date is:</B><BR>

<CFOUTPUT>
CFSET today = DateFormat(Now(), &quot;dddd, mmmm d, yyyy&quot;)><I>#today#</I></CFOUTPUT>
</DIV> <!---
The following is code that dynamically generates each question ---><CFOUTPUT query=&quot;get_question&quot;>
<FORM action=&quot;quiz_results.cfm&quot; method=&quot;post&quot;>
<P>
<HR><B>Your Question is:</B><BR><I>#question#</I><P>
<INPUT type=&quot;hidden&quot; name=&quot;today&quot; value=&quot;#today#&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;question_id&quot; value=&quot;#question_id#&quot;>

<INPUT type=&quot;radio&quot; name=&quot;user_answer&quot; value=&quot;#answer1#&quot;>#answer1#<BR>
<INPUT type=&quot;radio&quot; name=&quot;user_answer&quot; value=&quot;#answer2#&quot;>#answer2#<BR>
<INPUT type=&quot;radio&quot; name=&quot;user_answer&quot; value=&quot;#answer3#&quot;>#answer3#<BR>
<INPUT type=&quot;radio&quot; name=&quot;user_answer&quot; value=&quot;#answer4#&quot;>#answer4#<BR>

<P><INPUT type=&quot;submit&quot; value=&quot;Score Question!&quot;>
<INPUT TYPE=&quot;Button&quot; value=&quot;Get New Question!&quot;
ONCLICK=&quot;location.href='home.cfm'&quot;>
</FORM>
</CFOUTPUT>
</BODY>
</HTML>



this is from the quiz_results.cfm file

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>Quiz Results</title>
</head>

<body bgcolor=&quot;#ffffff&quot;>

<cfif NOT IsDefined(&quot;form.user_answer&quot;) OR
NOT IsDefined(&quot;form.question_id&quot;) OR
NOT IsDefined(&quot;form.today&quot;)>
<div align=&quot;center&quot;>
<hr><b>Welcome!</b><hr>
<i><a href=&quot;home.cfm&quot;>Please take my quiz!</a></i>
</div>
<cfabort>
</cfif>

<cfquery name=&quot;get_answer&quot; datasource=&quot;quiz&quot; dbtype=&quot;ODBC&quot;>
select question, correct_answer
from questions
where question_id = #form.question_id#
</cfquery>

<div align=&quot;center&quot;>
<hr><b>Quiz Results!</b>
<b>Thank you for taking my short quiz!</b><p>
</div>

<cfoutput query=&quot;get_answer&quot;>
<cfif user_answer IS correct_answer>
<b><font color=&quot;##008000&quot;>Congratulations!!! You are correct!</font></b><p>
<cfelse>
<b><font color=&quot;##ff0000&quot;>
I'm sorry, but that is the wrong answer. Please try again.</font></b><p>
</cfif>

<b>The question was:</b> #question#<br>
<cfif user_answer IS NOT correct_answer>
<b>Your answer was:</b> #form.user_answer#<br>
<b>The correct answer is:</b> #correct_answer#<br>
</cfif>
<b>You took the quiz on:</b> #form.today#<p>
</cfoutput>

<div align=&quot;center&quot;>
<i><a href=&quot;home.cfm?question_id=#question_id#&quot;>Take the quiz again?</a></i>
</div>

</body>
</html>

 
The problem could be in using the IsDefined(), because the variable could be defined but be blank. So you want to use both IsDefined() and something else like Len(). I add Trim() on the inside also because a space &quot; &quot; would evaluate to a length of 1, but Trim(&quot; &quot;) would evaluate to 0 because it removes the spaces.

You could try the following change:

<CFIF NOT IsDefined(&quot;question_id&quot;) OR NOT Len(Trim(question_id))>
<CFQUERY name=&quot;get_count&quot; datasource=&quot;quiz&quot; dbtype=&quot;odbc&quot;>
select count(question_id) as total_questions
from questions
</CFQUERY>
</CFIF>

<CFQUERY NAME=&quot;get_question&quot; DATASOURCE=&quot;quiz&quot; DBTYPE=&quot;odbc&quot;>
SELECT question_id,
question,
answer1,
answer2,
answer3,
answer4
FROM questions
WHERE question_id =
<CFIF IsDefined(&quot;question_id&quot;) AND Len(Trim(question_id))>
#question_id#
<CFELSE>
#RandRange(1, get_count.total_questions)#
</CFIF>
</CFQUERY> - tleish
 
tleish thank you very much!!
thank you to everyone else that responded to my question. i really appreciate the help.



itsecsol
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top