Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
02-28-2008, 05:51 PM #1
- Join Date
- Dec 2005
- Thanked 0 Times in 0 Posts
PHP Q:empty()/redirect/include() ?
empty($_post['submit']) this returns what for button "submit" non pressed / pressed ?
empty($_post['firstname']) this returns what for firstname field equals "", " ", (novalue-and press submit) ?
May use and isset() rather than empty() above, is the same ?
how in php I redirect user to a specific page eg. retrieve.php ?
php's include("file.html"); ?
02-29-2008, 02:30 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,650 Times in 2,619 Posts
isset is not exactly related to empty.
Isset is used to determine the existence of a variable, while empty is used to evaluate what that data includes.
Empty is a boolean result set, so it will return either true or false, and since php is a loosely typecasted language, false == 0 and true != false.
In your examples:
empty($_POST['submit']) on a correct submit returns false
empty($_POST['submit']) on a non-posted form returns true
empty($_POST['firstName']) on a value of "" returns true
empty($_POST['firstName']) on a value of " " returns false
on a side note, the value "0" as a string is also considered empty.
Isset is my recommendation for forms, and error checking is handled with empty and trim values.
$_POST['firstName'] = trim($_POST['firstName']);
echo 'The value is empty, please enter the data.';
PHP redirects are done by adding headers to the request:
header('HTTP/1.1 420 Enhance Your Calm');