<!DOCTYPE html>
<html lang="hu">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="reg.css"/>
</head>
<body>
<h1>Delete (with url, GET and POST)</h1>
<?php
require_once('auth.php');
require_once('constants.php');
if(isset($_GET['id']) && isset($_GET['name']) && isset($_GET['picture']))
{
 $id=$_GET['id'];
 $name=$_GET['name'];
 $picture=$_GET['picture'];
 echo '<h3>Do you really want to delete '.$name.' <img src="'.PATH.$picture.'"/>?</h3>';
 
 echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
 echo '<p>yes<input type="radio" name="confirm" value="yes"/> no<input type="radio" name="confirm" value="no"/></p>';
 echo '<input type="hidden" name="id" value="'.$id.'"/>';
 echo '<input type="hidden" name="picture" value="'.$picture.'"/>';
 echo '<p><input type="submit" name="submit" value="Delete"/></p>';
 echo '</form>';
}

if(isset($_POST['submit']))
{
 if($_POST['confirm']=="yes")
 {
  $id=$_POST['id'];
  $picture=$_POST['picture'];
  $dbc=mysqli_connect(HOST, USER, PASSWD, DB) or die('Error connection...');
  $query="DELETE FROM participants WHERE id=$id";
  mysqli_query($dbc, $query) or die('Error...');
  mysqli_close($dbc);
  @unlink(PATH.$picture);
  echo '<h3>Participant has been deleted.</h3>';
 }
}
?>
<h2><a href="main.html">&lt;&lt;Back to the main page</a></h2>
</body>
</html>
