-2

None of the solutions in the other threads were clear. I need help removed the undefined message. The line of code that is causing it is this variable:

$ain = $_Get['AIN'];

Other threads mentioned using upset although I could not follow. I want to be able to pass a value in whether it is null or not.

Ivar
  • 6,138
  • 12
  • 49
  • 61
bprice
  • 1
  • 2
  • 3
    We can't tell you much more then is said in other threads based on that one line. You can try to [edit] your question to provide more detail on what you tried/what didn't make sense. – Ivar Jun 15 '19 at 20:42

2 Answers2

1

You have to check the existence of the array index before using it, and provide an alternative value to use in case it isn't set.

For example:

if(isset($_GET['AIN'])){
  //The value is set and you can use it
  $ain = $_GET['AIN'];
} else {
  //The value is not set, so you should provide a default value
  $ain = NULL;
}

Also note that the PHP language is case sensitive, so if you want to refer to HTTP GET parameters, you should use $_GET, because $_Get will not work.

salvatore
  • 511
  • 4
  • 11
0

Assuming you meant to reference the superglobal $_GET, you can use one of the following:

<?php
$ain = 'default';
if(isset($_GET['AIN']))
    $ain = $_GET['AIN'];

Or use the ternary:

<?php
$ain = isset($_GET['AIN']) ? $_GET['AIN'] : 'default';

Or the shortest with the null-coalescing operator:

<?php
$ain = $_GET['AIN'] ?? 'default';
Progrock
  • 7,373
  • 1
  • 19
  • 25