public function save() { 		
		$name = $this -> input -> post("name"); 
		$latitude = $this -> input -> post("latitude");
		$longitude = $this -> input -> post("longitude");
		$years = $this -> input -> post("years");
		$populations = $this -> input -> post("populations");
		$region_id = $this -> input -> post("region_id"); 
		//Check if we are in editing mode first; if so, retrieve the edited record. if not, create a new one!
		if(strlen($region_id)>0){
			
			 $region = Regions::getRegion($region_id); 
			 
			 //also, retrieve the region-population combinations for future comparisons. Delete the old ones
			 $region_populations = Regional_Populations::getAllForRegion($region_id);
			 foreach($region_populations as $region_population){ 
			 	$region_population->delete();
			 }
		}
		else{
			$region = new Regions();
		}
		
		$region -> name = $name; 
		$region -> latitude = $latitude;
		$region -> longitude = $longitude;
		$region -> save(); 
		$region_id = $region -> id;
		$counter = 0;  
		//Loop to get all the year-population combinations. Only add the ones that have actual values
		foreach ($years as $year) { 
			if (strlen($year)>1) { 
				$region_population = new Regional_Populations();
				$region_population -> name = $name;
				$region_population -> population = $populations[$counter];
				$region_population -> year = $years[$counter];
				$region_population -> region_id = $region_id;  
				$region_population -> save();
				$counter++;
			} else {
				$counter++;
				continue;
			}

		} 
		redirect("region_management");
	}