Solved

How to use filter_has_var in php?

Posted on 2011-02-27
3
580 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 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 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