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 8542889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:10:29+00:00 2026-06-11T12:10:29+00:00

currently I have a simple search query which works as follows: $username = $_SESSION[‘username’];

  • 0

currently I have a simple search query which works as follows:

$username = $_SESSION['username'];
$chosencategory = $_GET['category'];
$price = $_GET['price'];

$search = $_GET['search'];
$terms = explode(" ", $search);

if ($price && $chosencategory){
        $sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE) AND category='$chosencategory' ORDER BY price $price";
    $q   = $conn->prepare($sql) or die("failed!");
    $q->bindValue(':search',"%".$search."%",PDO::PARAM_STR);
    $q->execute();
    }

When a user chooses, for example, “display price lowest to highest” the value sent through to $_GET['price'] = ASC, however i am not sure if this is a safe way to sort the results, does anyone have a better way?

also this method is not the best as when the user choses a sort option such as “display price lowest to highest” the dropdown box echoes the value which has been sent to the $_GET[‘price’] which is “ASC” so in the dropdown box it reads ASC after the form as been sent!

Sorry if this is confusing please comment if you would like me to re-explain this, any help or advice is much appreciated!!

  • 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-06-11T12:10:30+00:00Added an answer on June 11, 2026 at 12:10 pm

    Related to your value binding and sql injection, you should also check that values are set before using. if you enabled error_reporting(E_ALL) you would see lots of Undefined warnings. Here are some tips/changes:

    <?php 
    // Check and set username
    $username = (isset($_SESSION['username']) ? $_SESSION['username'] : 'guest');
    
    // Check and set category
    $category = (!empty($_GET['category']) ? $_GET['category'] : null);
    
    // Check and set search
    if(!empty($_GET['search'])){
        $search = $_GET['search'];
        $terms  = explode(" ", $search);
    }else{
        $search = null;
        $terms  = null;
    }
    
    // Check that $_GET['price'] is ASC if not set to DESC
    // as static values its ok to directly put in the query 
    if(isset($_GET['price']) && $_GET['price'] == 'ASC'){
        $price = 'ASC';
    }else{
        $price = 'DESC';
    }
    
    if ($category !== null && $search !== null){
    
        $sql = "SELECT   *
                FROM     people
                WHERE    MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)
                AND      category = :category
                ORDER BY price ".$price;
    
        $q = $conn->prepare($sql);
        // Bind the params to the placeholders
        $q->bindParam(':search', $search, PDO::PARAM_STR);
        $q->bindParam(':category', $category, PDO::PARAM_STR);
        $q->execute();
        // Get result
        $result = $q->fetchAll(PDO::FETCH_ASSOC);
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple interface which needs to communicate between processes. It's currently
I currently have a simple form that when you click the save button will
Currently I have a simple knockoutJS object, with a few observables. But this object
Currently I have a simple maven project that is building a jar file and
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I own a video streaming website and currently I just have a simple hit
Very simple + silly question: Does clojure provide multi maps? I currently have something
I have a simple ticket logging application build on LAMP. I am currently playing
I have a (currently very simple) website that is utilising Facebook's Website with Facebook

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.