<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);

/*DEPRECATED Use version 2*/
/* The following code deletes a profile from the PROFILE table */

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['email'])){
	$email = $_POST['email'];
	
	// include db config class
	require_once __DIR__ . '/db_config.php';
	
	// connecting to db
    	$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
			
	//get friends reg id
	if($stmt = $mysqli->prepare("DELETE FROM PROFILE WHERE EMAIL = ?")){
		// Bind a variable to the parameter as a string. 
		$stmt->bind_param("s", $email);
		    		
		// Execute the statement.
		$result = $stmt->execute();
		
		// record has been deleted succesfully
		if($result){ 
			//return friends list
			$response["success"] = 1;
								 
			// echoing JSON response
			echo json_encode($response);
		}
		//else return error
		else{    					    		
			$response["success"] = 0;
			$response["message"] = mysqli_error($mysqli);
					 
			// echoing JSON response
			echo json_encode($response);
		}
		    		
		// Close the prepared statement.
		$stmt->close();      		    		    		
	}
	else{
    		$response["success"] = 0;
		$response["message"] = "Failed to delete data";
				 
		// echoing JSON response
		echo json_encode($response);
    	} 
    	
    	mysqli_close($mysqli);	
}
else{
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}

?>