Page 1 of 1

Cannot detect non-existent parameter in $_POST (PHP 5.1.4)

Posted: Fri May 19, 2006 4:54 am
by dsileo
Hi All - new user here :o

I have the following code fragment in a PHP ASP webpage:

Code: Select all

function getFromForm($p) {
	$x = $HTTP_POST_VARS[$p];          //or $_POST[$p] or $HTTP_GET_VARS[$p] or $_GET[$p], 
	if (is_null($x)) return "<none>";
	if ($x == "") return "<none>";
	return $x;
}

$x = getFromForm("clientid");
echo "|".$x."|";

this is run the first time I enter my web page - it always prints "||", which means the function is returning an empty string or a null string. On the first run of the page, the POST variable 'clientid' does not yet exist until I submit the form which is at the bottom of this page.

So why is the function not returning "<none>" as it is designed to do?

Leo 8)

Pllease help - I'm getting seriously desperate (I've wasted a whole worksday on this problem :x ) and am beginning to think I should switch to VBScript :?

Posted: Fri May 19, 2006 5:28 am
by Benjamin

Code: Select all

function getFromForm($x) {
   if (is_null($x)) return "<none>";
   if ($x == "") return "<none>";
   return $x;
}

$x = getFromForm($_POST['clientid']);
echo "|".$x."|";
Change $_POST to $_GET if you can see the data in the url address.

Posted: Fri May 19, 2006 10:01 am
by dsileo
I did try it with all combinations of the POST and GET arrays.

But the answer I discovered eventually for myself - it's so simple we should both be ashamed :oops:


Clue: try using "_none_" instead of "<none>" :wink:


Thanks for the reply tho'
Leo 8)