Solved

How to use filter_has_var in php?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Store image url and display it for user profile 6 23
Php pie charts 3 26
datetime in sql 6 28
Selecting SUM data from mysql table with PHP 4 6
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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.  …
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 …

910 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

23 Experts available now in Live!

Get 1:1 Help Now