View Full Version : PHP Q:empty()/redirect/include() ?
02-28-2008, 05:51 PM
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
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.';
For example. As I mentioned, special cases need to be done for numbers, as "0" in a string is empty, and I have no idea why they decided to program that way.
PHP redirects are done by adding headers to the request:
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.