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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:40:56+00:00 2026-05-21T20:40:56+00:00

I am novice PHP programmer and I have created a function that changes an

  • 0

I am novice PHP programmer and I have created a function that changes an SQL command. Here is relevant piece of code:

 $extra_text_length = strlen($_GET[extra_text]);
 $boolean = $_GET['first-boolean'];

 function check_boolean(){

  if($extra_text_length > 0){

    if($boolean=="and"){
        $query .= " AND (software.SWID='$_GET[extra_text]')";
        } elseif($boolean=="or"){
        $query .= " OR (software.SWID='$_GET[extra_text]')";
        } elseif($boolean=="not"){
        $query .= " NOT IN (software.SWID='$_GET[extra_text]')";
        }
    } return $boolean;
  }

check_boolean();

The problem is that it doesn’t do what it should do. If I remove the code from the function however and as consequence I remove the check_boolean() method it works perfectly. Would anyone give me a hint? Thanks in advance

  • 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-21T20:40:57+00:00Added an answer on May 21, 2026 at 8:40 pm

    Make sure to use the variable name $boolean instead of boolean, otherwise it’s trying to get a constant.

    You also have to be careful to what you pass to your method. $query is a variable that you haven’t defined either.

    Make sure to do something like this

     $extra_text_length = strlen($_GET[extra_text]);
     $boolean = $_GET['first-boolean'];
    
     function check_boolean($query, $extra_text_length, $boolean, $software){
    
      if($extra_text_length > 0){
    
        if($boolean=="and"){
            $query .= " AND ($software.SWID='$_GET[extra_text]')";
            } elseif($boolean=="or"){
            $query .= " OR ($software.SWID='$_GET[extra_text]')";
            } elseif($boolean=="not"){
            $query .= " NOT IN ($software.SWID='$_GET[extra_text]')";
            }
        }
        return $query;
      }
    
    $query = '...';
    $software = '';
    $query = check_boolean($query, $extra_text_length, $boolean, $software);
    

    Also, avoid using external variables in a function, since you don’t know how they will react. ($_GET)
    You should also check the existence of all your variables.

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

Sidebar

Related Questions

novice Perl programmer here!. I'm using the system() function to get the return code
I'm a novice php programmer and having a problem assembling this code to work.
I'm new here, also a novice programmer, and not really familiar with PHP. I
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I'm a novice when it comes to SQL and PHP, and I'm trying to
I want to deter novice users from seeing the source code. I have a
I am a novice in PHP. I have a URL and I need generate
I have a simple PHP script with a form that has two select fields,
I'm quite a novice at PHP. I would like the IP address that I
I am a complete novice at php and postgres. I have been searching all

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.