Page 1 of 1

Scope problem

Posted: Thu Apr 21, 2005 5:10 am
by harrisonad
Please help me with this.

Code: Select all

<?php
    $appid = $leavetype = $employeeid = $jobtitle = $companydept =  $fromdate = $todate = $reason = $depthead = '';
    
	function getDetails(){
		global $appid,$leavetype,$employeeid,$jobtitle,$companydept, $fromdate,$todate,$reason,$depthead;
		$employeeid = $_POST['employeeid'];
		$datefiled = $_POST['datefiled'];
		$jobtitle = $_POST['jobtitle'];
		$companydept = $_POST['companydept'];
		$leavetype =$_POST['leavetype'];
		$fromdate = $_POST['from_year']."-".$_POST['from_month']."-".$_POST['from_day'];
		$todate = $_POST['to_year']."-".$_POST['to_month']."-".$_POST['to_day'];
		$reason = $_POST['reason'];
		$superiorid = $_POST['superiorid'];
		$deptheadid = $_POST['deptheadid'];
		if($type=='edit')
			$appid = $_POST['appid'];	
	}
    getDetails();
    echo $employeeid; // This returns NULL
?>
will you tell why this happened?

Posted: Thu Apr 21, 2005 5:27 am
by phpScott
One of 2 possible reasons.
1) $_POST['employeeid'] doesn't have a value.
2) function getDetials doesn't know about your $_POST values, but this is unlikely as %_POST is a global variable.

re

Posted: Thu Apr 21, 2005 5:32 am
by harrisonad
but what if a put a:

Code: Select all

global $_POST;
in getDetails function, will it make sense?

Posted: Thu Apr 21, 2005 7:25 am
by Chris Corbyn
$_POST is actually a superglobal so will work within a function in any case...

Have you tried

Code: Select all

print_r($_POST);
Just so you know that you're getting what you believe should be transferred ?