<html>

<head>
<title>Films</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>

<?php
session_start();
if (isset($_SESSION['loggedin'])){
	//user in logen in. Show a message on the screen
	echo "I can see that you are logged in<hr/>";
} else {
	//redirect the user to the login form.
	session_destroy();
	header('Location: login.php');
}
?>

<div id="container">

	<div id="header">
	<! header picture in css >
	</div>
	
	<div id="navigation">
		<?php include 'navigation.php'; ?>
	</div>

	

<?php

//get the ID from the querystring.
$id=$_GET['id'];//get the value from the address bar



 // define variables and set to empty values
$confirmationErr = $confirmation = "";


if ($_SERVER["REQUEST_METHOD"] == "POST")
{
   $id= test_input($_POST["id"]);
   $confirmation = test_input($_POST["confirmation"]);
   
  if (empty($_POST["confirmation"]))
    {$confirmationErr = "(Confirmation is required)";}
  else
    {$confirmation = test_input($_POST["confirmation"]);}
	
}

function test_input($data)
{
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}

?>
<div id="aside">
<form method="LINK" action="films2.php">
<input type="submit" value="Ignore">
</form>
</div>

<div id="content">

<h1>Deleting</h1>

<p> Please confirm you want to delete? </p><br>


<p><span class="error">* required field.</span></p>
<form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

<form>
Confirmation:<span class="error">*</span><br>
<input type="hidden" name="id" value="<?php echo $id;?>">
<input type="radio" name="confirmation" value="yes">Yes<br>
<input type="radio" name="confirmation" value="no">No<br>
<span class="error"> <?php echo $confirmationErr;?> </span>

<input type="submit" name="Submit" value="Confirm"><br>
</form> 


<?php

switch ($confirmation)
{
case "yes";
$con = mysql_connect("localhost","******","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("******", $con);



$sql = "DELETE FROM php_films WHERE filmid='$id' ";
echo $sql;

if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}

//close the connection to the database.

mysql_close($con);
header('Location: films2.php');
break;

case "no";

header('Location: films2.php');
break;

default;

}
?>
</div>

<div id="footer">
Copyright &#169; Istvan Franko, 2014
</div>


</div>
</body>
</html>
