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 ?
How include files in html/xhtml and how on javascript just like
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.

if (isset($_POST['firstName']))
$_POST['firstName'] = trim($_POST['firstName']);
if (empty($_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:
header('Location: newpage.php');

HTML and Javascript are not really equipped to handle includes on their own (i'm not an HTML specialist, but from my experience). You need to use a server side language to get the data you require. AJAX is a semi-inclusion method, but still relies on both a client and server process to initiate it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum