February 19, 201610 yr I have used a "borrowed" simple PHP script to create a nice Contact Me page on my website at www.ve3oat.ca. Each time a visitor sends me a message, I get two errors in my error-log : PHP Notice: Use of undefined constant INPUT - assumed 'INPUT' in /home/veoatca/public_html/acknowledge.php on line 11 and PHP Notice: Use of undefined constant POST - assumed 'POST' in /home/veoatca/public_html/acknowledge.php on line 11 My line 11 contains : $email = filter_input(INPUT-POST, 'email', FILTER_VALIDATE_EMAIL); I am not a PHP programmer and wonder if anyone recognizes these errors and can point me to a solution. I assume I need to declare INPUT and POST somehow, but don't know how to do that. I do receive all the messages from visitors all right but the errors bug me and I want to fix them. Thanks for any help. ... Martin
February 19, 201610 yr The first parameter of input_filter is the type parameter and can be: typeOne of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV. http://php.net/manual/en/function.filter-input.php I'm guessing you want INPUT_POST (with an underscore) not INPUT-POST EDIT: Also You should not "declare INPUT and POST" the method will filter a post variable that should be send to the PHP page with your form (your form must have a method attribute with the value "post") <form method="post" action="yourphpscript.php"> <label for="email">Enter your e-mail</label> <input type="text" name="email"> <input type="submit" value="Submit"> </form> This form will pass a post type variable named email along with a request for "yourscript.php". The variable will be accessible in your PHP script like so $_POST['email'] In the filter_input method you supply the type and the variable name individually. filter_input([Type], [Variable name], [Filter] ); So if you want to validate the email send with the form above you would use filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); Edited February 19, 201610 yr by Nillervision
February 19, 201610 yr Author Thanks very much, Nillervision. I think I see now what I must do. Thanks for your help. This PHP stuff is certainly different from the assembler code I used to write for a DEC PDP-8/L, so many years ago! (More than 40, actually.) And I will have to do some more reading here too. :-) Thanks again! ... Martin
February 19, 201610 yr Thanks very much, Nillervision. I think I see now what I must do. Thanks for your help. This PHP stuff is certainly different from the assembler code I used to write for a DEC PDP-8/L, so many years ago! (More than 40, actually.) And I will have to do some more reading here too. :-) Thanks again! ... Martin You're welcome. I think if you give it a try you will find PHP great to work with. Here is a few things that is good to keep in mind First of all PHP is very much "high level" meaning that the code is very easy to read and understand for humans. PHP does not get compiled to low level byte code. It will be interpreted at runtime. Compared to JAVA and C#, PHP is relatively "loosely typed" meaning that often you dont have to specify or convert data types. For example: You can print out an int as a string or concatinate it with an existing string without having to manually convert it. Also when you create a variable you don't need type declarations if the value is in quotes it simply is a string, if the value is FALSE it simply is a boolean etc. The language is object oriented, which means that you can create classes. A class is a blue print function that can be instanciated as one or more objects (variables that contains all the properties and methods defined in the class). An instance of a class in not just a reference to the class but a full, unique "function" with it's own scope. The cool thing about OOP is that you will have all your variables encapsulated and you can specify at what level each property/method can be accessed. PHP is designed to drive web applications (as I know, the only real use for it). That means that the language has a lot of build in functions for web. The filter_input() that you asked about is just one of many web related functions. You also have functions for formatting urls, parsing XML/json, sending mail, processing images and many other functions designed for web development. On a PHP installation the default settings are stored in a php.ini file. Many settings can be overridden from your code.
February 19, 201610 yr You're welcome. I think if you give it a try you will find PHP great to work with. Here is a few things that is good to keep in mind First of all PHP is very much "high level" meaning that the code is very easy to read and understand for humans. PHP does not get compiled to low level byte code. It will be interpreted at runtime. Compared to JAVA and C#, PHP is relatively "loosely typed" meaning that often you dont have to specify or convert data types. For example: You can print out an int as a string or concatinate it with an existing string without having to manually convert it. Also when you create a variable you don't need type declarations if the value is in quotes it simply is a string, if the value is FALSE it simply is a boolean etc. The language is object oriented, which means that you can create classes. A class is a blue print function that can be instanciated as one or more objects (variables that contains all the properties and methods defined in the class). An instance of a class in not just a reference to the class but a full, unique "function" with it's own scope. The cool thing about OOP is that you will have all your variables encapsulated and you can specify at what level each property/method can be accessed. PHP is designed to drive web applications (as I know, the only real use for it). That means that the language has a lot of build in functions for web. The filter_input() that you asked about is just one of many web related functions. You also have functions for formatting urls, parsing XML/json, sending mail, processing images and many other functions designed for web development. On a PHP installation the default settings are stored in a php.ini file. Many settings can be overridden from your code. I should also mention regarding the above regarding point number 2 is that sometimes u will need a string to be an int in which you can do it like this <?php $a = (int) "5";//Cast string to integer ?>
February 19, 201610 yr Author Thanks for all the advice and insight. And of course I should have spotted the type myself, weeks ago!! Now I can concentrate on making things nice for the visitors. And make time to read the tutorials here. What a treasure this forum is! Thanks again. ... Martin
Create an account or sign in to comment