Solved

How to use filter_has_var in php?

Posted on 2011-02-27
3
589 Views
Last Modified: 2012-05-11
I tried writing an if statement like this:

if (filter_has_var(INPUT_POST, 'hw1')) {
      $hw1 = filter_input(INPUT_POST, 'hw1');
}
else {
      $hw1 = 100;      
}

But Its not working. I get this error message:

Notice: Use of undefined constant hw1 - assumed 'hw1' in /home/tleithof/htdocs/gradebook.php on line 13

Warning: filter_has_var() expects exactly 2 parameters, 1 given in /home/tleithof/htdocs/gradebook.php on line 13

Can someone please inform how to use this function corrently?? Thanks
0
Comment
Question by:FairyBusiness
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Dushan De Silva earned 500 total points
ID: 34993995
http://www.w3schools.com/php/func_filter_has_var.asp
http://www.w3schools.com/PHP/php_filter.asp
http://php.net/manual/en/function.filter-has-var.php
---------------------------------------------------------------------
if (filter_has_var(INPUT_POST, "hw1"))
{
      $hw1 = filter_input(INPUT_POST, "hw1");
}
else {
      $hw1 = 100;      
}
---------------------------------------------------------------------
<?php
if(!filter_has_var(INPUT_POST, "url"))
  {
  echo("Input type does not exist");
  }
else
  {
  $url = filter_input(INPUT_POST, "url", FILTER_SANITIZE_URL);
  }
?> 

----------------------------------------------------------------------

Open in new window

0
 

Author Comment

by:FairyBusiness
ID: 34994008
I dont see how you changed my code.  But does the function not work unless you use ! before it??
0
 

Author Closing Comment

by:FairyBusiness
ID: 34994085
Ok, yes you must use !
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question