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

  • SEARCH
  • Home
  • 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 8711435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:52:35+00:00 2026-06-13T04:52:35+00:00

I am trying to $_GET some variables that a user may enter (busy making

  • 0

I am trying to $_GET some variables that a user may enter (busy making a basic web-server):

$users= strval($_GET['user']);
$price= intval($_GET['price']);
$productID= intval($_GET['productid']);

This is my query:

$query = "SELECT * FROM `table` WHERE `user` = '" . $user . "' AND `price` <= " . $price . " AND `productID` = " . $productID; 

(something like this)

Given this theoretical link:

www.example.com/api.php?price=300

And don’t use the rest of the GET (user and productID) will automatically be filled with either 0 or ” (int/string).

So I thought I could use an if statement:

if(price == 0){
   // change the query without the price as WHERE
}

But what if I have combinations of price and productID or productID and user as variables.

What is the best way to handle this? Maybe it’s a stupid question but I can’t figure it out.

  • 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-13T04:52:36+00:00Added an answer on June 13, 2026 at 4:52 am

    You can use combined IF statements to build the appropriate query using the variables if they are supplied (and ignoring them if not)

    $query = "SELECT * FROM `table` WHERE 1"; // WHERE 1 means "return all rows from table"
    
    if ( isset( $_GET['price'] ) ){ // Only if price variable is set
        $query .= " AND price <= '{$_GET['price']}'"; // Restrict results by price
    }
    
    if ( isset( $_GET['user'] ) ){ // Only if user variable is set
        $query .= " AND user LIKE '{$_GET['user']}'"; // Restrict results by user
    }
    
    if ( isset( $_GET['productID'] ) ){ // Only if user variable is set
        $query .= " AND productID = '{$_GET['productID']}'"; // Restrict results by productID
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to test some code that reconnects to a server after a disconnect.
I'm trying to get some data from a certain web-based api using the libcurl
I'm trying to prevent some basic click-fraud on my site, and am building links
I am trying to get some data from the user and send it to
I am trying to embed some ajax in my project. What happens is that
I'm trying to pass some variables using jquery and ajax but for some reason
I have some simple text file. I am trying to read that file contents
I have some code where I am trying to use variables in a tabpage.
I am trying to generate some Javascript for a Comet callback. The code that
So I'm trying to write a php SOAP client that requires the user to

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.