Solved

How to use filter_has_var in php?

Posted on 2011-02-27
3
575 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:
Dushan911 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now