last question today! promise!

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
hc
Forum Newbie
Posts: 13
Joined: Wed Oct 25, 2006 2:00 pm

last question today! promise!

Post by hc »

I have the following function that expects and array called $data. How do I get the following form posts into the array that will be used when I call this function? I did not write these functions. Though I have a programming background, its not PHP, so any help is appreciated. I promise you wont have to explain it more than once! :wink:

$found = false;
$client = $_POST['client_' . $val];
$home = $_POST['home_' . $val];
$away = $_POST['away_' . $val];
$sport_id = $_POST['sportid'];
$teamname = '';
$team_id = -1;
$true = true;
$false = false;

Code: Select all

		/********************************************************
		void AddTeam($data);

		Description:
			This will add a Team for $this->employer_id
	********************************************************/
	function AddTeam($data)
	{
		$retval = false;
		if($this->EmployerExists($this->employer_id))
		{
			if(!$this->GetTeamLink($data['team_id']) )
			{
				$sqlstr = <<< SQL
					INSERT INTO
						businesses.employer_team (employer_id, team_id, home, away)
					VALUES ($this->employer_id, $data[team_id], $data[home], $data[away])
SQL;
			}
			else if(!$this->TeamState($data))
			{
				$sqlstr = <<< SQL
					UPDATE
						businesses.employer_team
					SET
						status_id = 1,
						home = $data[home],
						away = $data[away]
					WHERE
						employer_id = $this->employer_id AND
						team_id = $data[team_id]
SQL;
			}

			if($this->Load($sqlstr))
			{
				$retval = true;
			}
		}
		return $retval;
	} // AddTeam()
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Instead of making them all like....

Code: Select all

$found = false;
$client = $_POST['client_' . $val];
$home = $_POST['home_' . $val];
$away = $_POST['away_' . $val];
$sport_id = $_POST['sportid'];
$teamname = '';
$team_id = -1;
$true = true;
$false = false;
Make them like

Code: Select all

$array['found']= false;
$array['client'] = $_POST['client_' . $val];
$array['home']= $_POST['home_' . $val];
$array['away'] = $_POST['away_' . $val];
$array['sport_id']= $_POST['sportid'];
$array['teamname'] = '';
$array['team_id'] = -1;
$array['true'] = true;
$array['false'] = false;

// To call it
AddTeam($array); 

// You can name array to anything you want.
-NSF
hc
Forum Newbie
Posts: 13
Joined: Wed Oct 25, 2006 2:00 pm

Thanks, appreciate it..

Post by hc »

thank you
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you are asking about getting information from $_POST, it is a superglobal and available to you in the global scope of the app.
Post Reply