0

Hey i working for my campus project so i want to ask what this notice means

Notice: Use of undefined constant angle_x - assumed 'angle_x' in C:\xampp\htdocs\lews\data.php on line 193

this is my php code

if(strlen($row->angle_x > 170 && angle_x < 185) ){
            echo"SIAGA LONGSOR";
            }

i've tried this method

if(strlen($row['angle_x'] > 170 && ['angle_x'] < 185) ){
            echo"SIAGA LONGSOR";
            }

but it comes error like:

Fatal error: Uncaught Error: Cannot use object of type stdClass as array in C:\xampp\htdocs\lews\data.php:190 Stack trace: #0

also tried this

if(strlen($row->'angle_x' > 170 && 'angle_x' < 185) ){
                echo"SIAGA LONGSOR";
                }

result:

Parse error: syntax error, unexpected ''angle_x'' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\lews\data.php on line 190 i tried any solution to fix this, but not truly help me out

Fawwaz
  • 37
  • 1
  • 10
  • This is just a typo. if you mean `strlen($angle_x)` use that, if you mean `strlen($row->angle_x)` use that, if you mean `strlen($row['angle_x'])` use that each time you want to make the comparison. We don't know, so we cannot answer. – mickmackusa May 15 '18 at 08:03
  • to expand a bit what other have said: variables in php must beginn with a `$`..if they are an object, you can access parts of the object with `$thing->part`, if they are an array, you can access the content with `$thing['element']`...this is very basic PHP ;) – cypherabe May 15 '18 at 08:07
  • The error is about `angle_x` from `angle_x < 185`. It should probably be `$row->angle_x`. – axiac May 15 '18 at 08:11

1 Answers1

2

the code should look like this:

if(strlen($row->angle_x) > 170 && strlen($row->angle_x) < 185){
   echo 'SIAGA LONGSOR';
}
Igor Ilic
  • 1,355
  • 1
  • 12
  • 19
  • hey the code works great! thank you! but what's the different ' and " ? that's have effect on my code? sorry im new at this – Fawwaz May 15 '18 at 08:13
  • 1
    The difference is that in the second part of your IF statement you used angle_x instead of $row->angle_x and in PHP if you type something without $ symbol it expects it to be a constant (see here: https://secure.php.net/manual/en/language.constants.php ) Also, the function strlen takse only one parameter and you were writing you entire if statement in it – Igor Ilic May 15 '18 at 08:21
  • what if i not using strlen function? just an IF function? – Fawwaz May 15 '18 at 08:38
  • i found another problem that the echo is not showing up the text – Fawwaz May 15 '18 at 08:45