I'm only two days old into learning PHP and i've gotten very far - but this one has me stumped. On a PHP page that retrieves form data, I have this instruction: $userData = $_POST['formData']; For error handling if formData isn't present, I figure that, like most every other scripting language I've worked with, I just check to see if $userData is null - however, if formData isn't present the above line kicks out an error of "Undefined index". What am I missing? Can someone please tell me how do I check if formData isn't present?
try this: if(!empty($_POST['formData'])){ $userData = $_POST['formData']; } i hope it will help.. Good luck!
Thank You! Also, BTW, is this the PHP command like "On Error Resume Next": ini_set('display_errors', 0);
No, you set display_errors to output the errors to the browser screen or not. You want it on when you are debugging, and off when you are in production. Look up try/catch statements to understand error handling in php.
@error_reporting( E_ALL & ~E_NOTICE); PHP: If you try this, I promise you, you will pretty soon be addicted to this function http://www.w3schools.com/php/php_error.asp http://www.php.net/manual/en/function.error-reporting.php
BTW - the PHP page I've built is called via serverXMLHTTP. So, I want to log errors to a file, but I am also using serverXMLHTTP to check the status of the page and if it is not = 200, I log the error. So I do want the page to return an error status.
I was figure the same problem with "undefined index". I read that undefined index is for bug checking function for development process and not for live.
PHP will not report any error. You can simply check this if($_POST['formdata']!="") , because PHP will evaluate $_POST['formdata'] as NULL if it's not set.
No, it's throwing an error. I'd rather implement a robust error-checking mechanism on my own, than leave it to chance.