-1
<?php 
    // Check for posted data
    if(filter_has_var('INPUT_POST', 'data')){
        echo 'Data Found';
    } else {
        echo 'No Data';
    }
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  <input type="text" name="data">
  <button type="submit">Submit</button>
</form>

I get this error and the input is not changing to "Data Found" when I submit a data.

Warning: filter_has_var() expects parameter 1 to be int, string given in /Applications/MAMP/htdocs/php_front_to_back/filters.php on line 3 No Data

Dharman
  • 30,962
  • 25
  • 85
  • 135
Jun Jung
  • 405
  • 5
  • 19
  • 1
    You want `INPUT_POST`, without quotes. That's a constant. See [the manual](https://www.php.net/filter_has_var) for examples. – Jeto Aug 22 '20 at 16:05

1 Answers1

0

You can use the below code:

if(filter_has_var(INPUT_POST, 'data')){
   echo 'Data found';
}else{
   echo 'No Data';

Enclosing with ' means that is a string, you must pass PHP constant in the first parameter.

First parameter supports : INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, INPUT_ENV