?
Solved

How to use filter_has_var in php?

Posted on 2011-02-27
3
Medium Priority
?
602 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
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Dushan De Silva earned 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

831 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