<?php



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



//check the id passed
if(isset($_POST['state']))
{
	$id =  $_POST['state'];
}


//validate the contractor name
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>';
   
   
}



//validate the address
$description = (!empty($_POST['description']))? (mysqli_real_escape_string($dbc,$_POST['description'])): 
 NULL;
$_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['title']);
	unset($_SESSION['description']);
	
	
	
	 //check if the query is for adding den add
	
	
		$q = "UPDATE `state` SET `title`= '$title',`description`='$description',`date_modified`=NOW() 
			WHERE id = '$id'";
										
							
	$r = mysqli_query($dbc,$q);
	
	if($r)
	{
		$info_success['success'] = 'Updated Successfully!';
		header("Location: gateway.php?act=view_states&is=".urlencode($info_success['success']).""); //is - info success
		
	}
	else
	{
		$errors['error'] =  'Not updated due to a system error. We apologize for any inconvenience.';
										
		header("Location: gateway.php?act=view_states&error=".urlencode($errors['error'])."");
	}
	
}
else
{//stay back in add_project form


	$errors['error'] =  'Details not updated, Please re-select and Fill the form appropriately, take note of <span class="ast">*</span>.';
										
	header("Location: gateway.php?act=view_states&error=".urlencode($errors['error'])."");

}



?>