<?php



$errors = array();
$info = array();
$info_success = array();






//validate the title
if(!empty($_POST['title']))
{
   $title = mysqli_real_escape_string($dbc, $_POST['title']);
   
   //collect code to fill the static form
   $_SESSION['title'] = $title;
 
}
else
{
   $errors[] = '<p> * </p>';
   
   
}


//check the state
if($_POST['state'] == '0')
{
	  $errors[] = '<p> * </p>';
   
}
else
{
 	$state = mysqli_real_escape_string($dbc, $_POST['state']);
   
   //collect code to fill the static form
   $_SESSION['state'] = $state;
   
   
}
//end of check state


  
  
$description =(!empty($_POST['description']))? mysqli_real_escape_string($dbc, $_POST['description']):NULL;
 //collect id to fill the static form
$_SESSION['description'] = $description;






//finaly get security id
$user_id = get_user_id();


$security_id = get_security_id($user_id);



 
 
 
if(empty($errors))
{
	//destroy session if there is no error
	unset($_SESSION['description']);
	unset($_SESSION['title']);
	unset($_SESSION['state']);
	
	
	
	
	 //check if the query is for adding den add
	
	
		$q = "INSERT INTO `lga`(`id`, `title`, `description`, `state_id`, `date_added`, `added_by`) VALUES (NULL , '$title', '$description','$state' ,
			 NOW(), '$security_id')";
							
							
	$r = mysqli_query($dbc,$q);
	
	if($r)
	{
		$info_success['success'] = 'Successfully added!';
		header("Location: gateway.php?act=view_lgas&is=".urlencode($info_success['success']).""); //is - info success
		
	}
	else
	{
		$errors['error'] =  'Not added due to a system error. We apologize for any inconvenience.';
										
		header("Location: gateway.php?act=add_lgas&error=".urlencode($errors['error'])."");
	}
	
}
else
{//stay back in add_project form


	$errors['error'] =  'Fill the form appropriately, take note of <span class="ast">*</span>.';
										
	header("Location: gateway.php?act=add_lgas&error=".urlencode($errors['error'])."");

}



?>