Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6758345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:46:30+00:00 2026-05-26T13:46:30+00:00

I’m extending a cakePHP 1.3.13 site and my user needs to be able to

  • 0

I’m extending a cakePHP 1.3.13 site and my user needs to be able to practically generate their own SELECT queries on some data via a web app. They were literally querying an MS Access database before but they will now have to use form controls to search via the site, but they are used to and require a degree of flexibility.

They’re searching through tickets and there are a couple of SELECT fields they don’t always need to see and a couple of WHERE conditions they don’t always need to filter by, and I’m trying to find out how to allow the functionality without adding the security wholes of dynamic SQL.

Here’s my find method:

$tickets = $this->Hauler->find('all', array(
        'conditions'=>array("ticketDate between'$startDate' and '$endDate'", "LocationID='$plant_id'", 'paid=0'),
        'fields'=>array('LocationID','OrderID','TicketDate','TicketNo','FreightPay','Qty','Total', 'Paid'),
        'order'=>array('TicketDate', 'LocationID','OrderID'),
        ));

The only ways I can think to include dynamic fields would either be use if statements to select one of a predefined set of all possible combinations of fields (not scalable, annoying) or to create a $fields array to append to the [fields] key.

The conditions have similar issues and I’m already uncomfortable including string concatenation like between '$startDate' but I don’t know of a better method there. CakePHP claims they sanitize for me if I use the find() method but I’m not sure how well.

Is there a specific method to allow these “dynamic” searches without risky actually dynamic SQL? I would like to continue to use CakePHP’s ‘find()’ method, I know Stored Procedures allow me to do just this, but this is a case where I want the logic in the code. Also, should I take additional sanitization steps beyond what Cake’s find() method does in any case?

I only have two very trusted users so security isn’t the biggest concern in this exact search, but I’d really like to know how to do this sort of find properly.

Update: I’ve updated my code and solved the fields problem as per @Anh Pham’s suggestion, but I still can’t get optional conditions working yet. Here’s my new code:

        $tickets = $this->Hauler->find('all', array(
        'conditions'=>array('Hauler.ticketDate BETWEEN ? AND ?' => array($startDate,$endDate), 'Hauler.LocationID'=>$plant_id, 'Hauler.paid'=>0),
        'order'=>array('TicketDate', 'LocationID','OrderID'),
        ));

This generates queries like WHERE LocationID='' if LocationID is not submitted via the form, instead of checking for an empty string I would like my query to omit the LocationID= portion of the WHERE clause if no LocationID is provided.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:46:31+00:00Added an answer on May 26, 2026 at 1:46 pm

    First:

    $tickets = $this->Hauler->find('all', array(
      'conditions'=>array('Hauler.ticketDate BETWEEN ? AND ?' => array($startDate,$endDate), 'Hauler.LocationID'=>$plant_id, 'Hauler.paid'=>0),
      'order'=>array('TicketDate', 'LocationID','OrderID'),
    ));
    

    Users can only see fields that you output, not all fields in the results. create a $fields array to append to the [fields] key, which is obviously unsafe. I don’t see how it’s unsafe.

    Cake’s find() shields you from SQL injection. So I don’t really see a security issue here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.