0

I have used $value = (isset($_REQUEST['value'])) to define the index variable. However, $value variable shows as a type Boolean and value of 0 or 1 in the debugger, which results in not getting the correct results when the $value is used with a (if) statement.

$page_limit = (isset($_REQUEST["list_page"]));

$viewdate = (isset($_REQUEST["viewdate"]));

How do I correct the following so that the index is defined?

if($_REQUEST["viewdate"] == '') {

      $viewdate = 'All';
  } else {

    $viewdate = $_REQUEST["viewdate"];
    }

$targetpage = "newindex.php?viewdate=".$_REQUEST["viewdate"]."&search=Search";           

$page = (isset($_REQUEST['page']));

if($page_limit == '') {

The code above works, without the isset() function, but displays Notice - E messages

Federkun
  • 36,084
  • 8
  • 78
  • 90
Barrington
  • 25
  • 6
  • 2
    have you saw the documentation of [isset](http://php.net/manual/en/function.isset.php)? – Federkun Oct 19 '15 at 00:09
  • Compare then set the value based on the comparison, http://php.net/manual/en/language.operators.comparison.php. One example from there, `$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];`. – chris85 Oct 19 '15 at 00:16
  • This corrected my problem!!! – Barrington Oct 24 '15 at 14:24

1 Answers1

1

You should use isset to test whether a variable has been set, then assign the value. Like so:

$something = null;
if (isset($_REQUEST['something'])) {
    $something = $_REQUEST['something'];
    ...
}
// Later in the code 
if ($something !== null) {
    // Do stuff
user2182349
  • 9,569
  • 3
  • 29
  • 41