<?php 
session_start();

if (isset($_SESSION["user_id"]) and isset($_SESSION["password"])) {
	$dbhost=$_SESSION["dbhost"];
	$dbuser=$_SESSION["dbuser"];
	$dbpass=$_SESSION["dbpass"];
	
	$id=$_SESSION["user_id"];
	header('Content-Type: application/json');

	$todo_id=$_POST["todo_id"];
	$e_title=strip_tags($_POST["e_title"]);
	$e_desc=strip_tags($_POST["e_desc"]);
	$e_todo=strip_tags($_POST["e_todo"]);

	$pdo=new PDO($dbhost,$dbuser, $dbpass);
	$sql="UPDATE todo SET todo_title=:e_title, todo_desc=:e_desc, todo_todo=:e_todo WHERE todo_id=:todo_id AND user_id=:id";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(
		':id' => $id,
		':todo_id' => $todo_id,
		':e_title' => $e_title,
		':e_desc' => $e_desc,
		':e_todo' => $e_todo,
	));
	unset($_POST);
	header("Location: ./todo.php#divider");
}
?>
