8 Replies - 1840 Views - Last Post: 08 March 2012 - 06:14 PM Rate Topic: -----

#1 De.camm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 12

Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 01:29 AM

<p>
<cfquery datasource="RegStudent" name="DisplaySearchingData" >
            select * from student
            WHERE 1=1
            <cfif  #Form.SName# NEQ ''>
            	AND firstname LIKE '%#Form.SName#%'
                <cfelse >
                AND mykad LIKE '%#Form.MyKad#%'
            </cfif>
            ORDER BY firstname, lastname
</cfquery>
</p>


Is it any wrong with my coding?

This post has been edited by Craig328: 07 March 2012 - 06:31 AM
Reason for edit:: Please use CODE tags when posting code samples


Is This A Good Question/Topic? 0
  • +

Replies To: Error when i try to combining 2 form name in if else

#2 Craig328  Icon User is online

  • I make this look good
  • member icon

Reputation: 1866
  • View blog
  • Posts: 3,389
  • Joined: 13-January 08

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 06:32 AM

Um...that would depend. What does the error message say?
Was This Post Helpful? 0
  • +
  • -

#3 De.camm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 12

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 07:03 AM

The error message said that line no 8
AND mykad LIKE '%#Form.MyKad#%'
is the problem,
the coding cannot execute.
Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is online

  • I make this look good
  • member icon

Reputation: 1866
  • View blog
  • Posts: 3,389
  • Joined: 13-January 08

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 07:17 AM

Can you copy/paste the exact CF error message?

In the meantime, right above the CFQUERY do this:
<cfdump var="#form#"><cfabort>


Make sure you actually HAVE a form element called MyKad and that is has a value.
Was This Post Helpful? 0
  • +
  • -

#5 De.camm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 12

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 08:44 AM

The exact error message is like attachment given.
Was This Post Helpful? 0
  • +
  • -

#6 Craig328  Icon User is online

  • I make this look good
  • member icon

Reputation: 1866
  • View blog
  • Posts: 3,389
  • Joined: 13-January 08

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 08:47 AM

No attachment.

Your original query looks to be okay as far as I can tell. The SQL syntax is correct and I'm assuming you've spelled the table names and columns correctly (if it's MySQL you may want to make sure the case spelling is identical). The exact error message text will tell you what's wrong.
Was This Post Helpful? 1
  • +
  • -

#7 De.camm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 12

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 08:58 AM

View PostCraig328, on 07 March 2012 - 07:17 AM, said:

Can you copy/paste the exact CF error message?

In the meantime, right above the CFQUERY do this:
<cfdump var="#form#"><cfabort>


Make sure you actually HAVE a form element called MyKad and that is has a value.


The exact CF error message is given in jpeg file in attachment named "message_error.jpg" , after i do the code
<cfdump var="#form#"><cfabort>
, i got the small table like image given named "error_msg_after put new code.jpg".

i do have a form element called MyKad, i enclose the coding with
 <br/>
<table width="30%" align="center">
<form id="form1" name="form1" method="post" action="">
<tr>
<td>Student Name :</td>
<td width="20%"><input type="text" value="" size="35" name="SName" id="SName"  style="text-transform:uppercase;"/></td>
</tr>
<tr>
<td>MyKad No. :</td>
<td width="20%"><input type="text" name="Mykad" size="35" value="" /></td>
</tr>
<tr>
<td colspan="2"><div align="center">
  <input type="submit" name="Search Student" value="Search" onclick="DisplaySearchingData"/>
  &nbsp;<input type="Reset" name="ResetForm" value=" Reset" />
</div></td>
</tr>
</form>
</table>
<br/> 

Attached image(s)

  • Attached Image
  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#8 Craig328  Icon User is online

  • I make this look good
  • member icon

Reputation: 1866
  • View blog
  • Posts: 3,389
  • Joined: 13-January 08

Re: Error when i try to combining 2 form name in if else

Posted 07 March 2012 - 09:10 AM

Well, the error message and the CFDUMP of the form scope say it all: you don't have a form.Mykad available to use in the query.

There's a few ways to remedy this (using a few CFPARAMs, adding a CFIF block in your code specifically referencing "form.Mykad" before you try and use it in the WHERE statement) but your best bet is to figure out and understand why, if you're putting a value into that field, that it's not appearing on the form processing page.

Absent both the form and form process page I can't tell you what's causing your problem but the problem itself is that form.Mykad doesn't exist as far as CF is concerned when it's trying to run your query.
Was This Post Helpful? 2
  • +
  • -

#9 De.camm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 12

Re: Error when i try to combining 2 form name in if else

Posted 08 March 2012 - 06:13 PM

Thanks Craig~ my search button can detect any number element in Mykad text field input already..
Firstly I try to declare the "form.mykad" one line in "form.sname" declaration, but its not work. After I separate the declaration then its working... Thanks for guide me to success...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1