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
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
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.