Scope problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Scope problem

Post 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?
Last edited by harrisonad on Thu Apr 21, 2005 5:28 am, edited 1 time in total.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
Last edited by phpScott on Thu Apr 21, 2005 5:54 am, edited 1 time in total.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

re

Post by harrisonad »

but what if a put a:

Code: Select all

global $_POST;
in getDetails function, will it make sense?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ?
Post Reply