ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 19th, 2005, 06:52 AM
tycoon tycoon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 50 tycoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 51 sec
Reputation Power: 5
Paging Issue

Hi all ...I'm kindda in a jam righ now...well what I'm trying to do is a simple search of my db...it work perfect until
i try to implement record paging on the result page (searchemp2.cfm)..an error of

Code:
The error

"Element FIELDNAME is undefined in FORM.  
 
  
The error occurred in C:\CFusionMX\wwwroot\epaihris\searchemp2.cfm: line 3
 
1 : 
2 : <cfquery name="result" datasource="epa">
3 : Select * from employee where #Form.fieldname# LIKE '%#trim(Form.sitem)#%'
4 : </cfquery>
5 : <CFPARAM name="URL.currentrow" default="1">"


does any one know how to settle this prob....i attach my code below

Code:

 search page (searchemp1.cfm)

[search page (searchemp1.cfm)]
<form action="searchemp2.cfm" method="post" name="form1">
  <span class="style1">Search on</span>
  <select name="fieldname" id="fieldname">
    <option value="full_name" selected>Employee Name</option>
    <option value="emp_no">Employee No</option>
  </select>
  <span class="style1">for</span>
  <input name="sitem" type="text" id="sitem">
  <input type="submit" name="Submit" value="Submit">
</form>


Code:

result page (searchemp2.cfm)

[result page (searchemp2.cfm)]
<cfquery name="result" datasource="epa">
Select * from employee where #Form.fieldname# LIKE '%#trim(Form.sitem)#%'
</cfquery>
<CFPARAM name="URL.currentrow" default="1">
<cfset qmaxrows = 10>
<CFSET next = URL.currentrow + qmaxrows>
<CFSET prev = URL.currentrow - qmaxrows>
<cfset qtotal = result.recordcount>
<cfset thispagemax = (qmaxrows + url.currentrow) - 1>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="css/zulpunya.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="500" border="0" align="center" id="overall">
  <tr>
    <td width="802" height="258" valign="top"><div align="center">
      <table width="425" id="navigation" >
	<tr>
	<td width="590" height="30" >Navgation Bar </td>
	</tr>
	</table><table width="472" id="pgcontent">
	<tr>
	<td width="464" height="59"><cfif result.RecordCount GT 0>
	  <table width="413" class="nicetableheader">
	    <tr class="nicetableheader">
	      <td width="89">Emp No </td>
	       <td width="215">Name</td>
	        <td width="93">&nbsp;</td>
	    </tr>
	    </table>
	  <table width="414" border="0" class="nicetablerow">
          <cfoutput>
              <tr class="nicetablerow">
                  <td width="86">#result.emp_no#</td>
                  <td width="218">#result.full_name#</td>
                  <td width="88">Detailed...</td>
              </tr>
          </cfoutput>        </table>
	  </cfif>      &nbsp;&nbsp;<span class="content"><a href="searchemp2.cfm?currentrow=#prev#">Previous</a>&nbsp;&nbsp;<a href="searchemp2.cfm?currentrow=#next#">Next</a></span><br>
        <cfoutput class="content">Showing #URL.currentrow# - 
              <cfif thispagemax GT qtotal>
                #qtotal#
                <cfelse>
                #thispagemax#
              </cfif> 
              of #qtotal# records.
        </cfoutput>        <table width="415" border="1">
        <tr>
          <td width="405" class="nicetableheader">No Result Found </td>
        </tr>
      </table>
      <p>&nbsp;</p>
        
          <br>
          <br></td>
	</tr>
	</table></td>
  </tr>
</table>
</body>
</html>

Reply With Quote
  #2  
Old June 19th, 2005, 10:58 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
Well, on subsequent pages you must not be posting the form again, so the fieldname form field is not present beyond the first page. One solution is to pass the fieldname as a URL variable or set it as a session variable so that you can use it on the on the other pages.

As a side note, letting the user dynamically set the name of the table being selected from is a pretty huge security hole...what if they tell the query to hit the users table (if you have one)? They could then see all the user names and passwords, etc. For a simple app you might not care, but if this were a professional application you probably wouldn't want to do this.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old June 19th, 2005, 09:34 PM
tycoon tycoon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 50 tycoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 51 sec
Reputation Power: 5
thanx for comennt kiteless...so can u give me some pointer to make this application more secure

Reply With Quote
  #4  
Old June 19th, 2005, 11:54 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
Hard coding the name of the table is the most secure option, but it means having a separate query for each table. It's also not good practice to "select *", you should really be selected the desired columns by name or alias, which is another reason to have separate queries. At the very least you should have some sort of validation that inspects the value of form.fieldname to confirm that it is a valid table name.

Reply With Quote
  #5  
Old June 20th, 2005, 05:04 AM
tycoon tycoon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 50 tycoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 51 sec
Reputation Power: 5
where can get more information or tutorial on doing these

Reply With Quote
  #6  
Old June 20th, 2005, 08:03 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
Which part needs more explaining? To me they're fairly striaghtforward (don't "select *", use column names; and don't use a variable for the table name, either hard code the table name or validate the variable to ensure it matches table names that you want to allow users to query).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Paging Issue


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT