Jump to content

Variable from one Function to another


JarrodCoder

Recommended Posts

Hi guys,

I'm trying to use the user input submitted and given to registerStageOne(). It's given by parameters in the function, then it returns the array. Here's the code:

 

userCore.php

class userCore {
		
		public $registerStageOne = array();
		public $registerStageTwo = array();
		
		
		public function registerStageTwo($d, $m, $y, $g) {
		require_once("cmsCore.php");
			$registerStageOne = array($d, $m, $y, $g);
			return $registerStageOne;
		}
		
		public function registerStageThree($u, $e, $p, $rp) {
			if($p==$rp) {
				echo 'they match!';
				$registerStageTwo = array($u, $e, $p, $rp);
				echo $registerStageTwo[1];
				
			}
			else {
				echo 'Your Passwords do not match!';
			}
		}
		
	}
	
$userCore = new userCore();

register.php:

<?php
	if(!isset($_GET['stage'])) {
		require_once($obj->getTPLDir() . "register-one.tpl");
	} else {
		switch($_GET['stage']) {
			case "2":
			if(empty($_POST['bean_day']) || empty($_POST['bean_month']) || empty($_POST['bean_year'])) {
				echo 'you have not filled out the form.';
			}
			$usersCore->registerStageTwo($_POST['bean_day'],$_POST['bean_month'],$_POST['bean_year'],$_POST['bean_gender']);
			require_once($obj->getTPLDir() . "register-two.tpl");
			break;
			
			case "3":
			$usersCore->registerStageThree($_POST['bean.name'], $_POST['bean.email'], $_POST['bean.password'], $_POST['bean.retypedPassword']);
			// require_once($obj->getTPLDir() . "register-three.tpl");
			break;
		}
	}
?>

I want to take the data from $usersCore->registerStageTwo() and hold it (or pass it down to $usersCore->registerStageThree()) the reason I want it here is so that I can import it into the database at the end of stage three.

 

Many thanks for your help.

 

Link to comment
https://forums.phpfreaks.com/topic/278594-variable-from-one-function-to-another/
Share on other sites

that's not really an object.  You have basicly written procedural code and wrapped an object container around it, you could actualy take away the class{} from the outside of that code, drop the scope deffinitions and that would work just as it is in the raw page.

 

Some key points to address -

you have echo's within the methods within your object

you never actually assign anything to your objects parameters

you have a require within your object

you have everything as public

and - not specific to oop, but - you have a method named the same as a parameter

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.