<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
  <title>Kolej Vokasional Sepang - E-Vote</title>
</head>



<body>
   
 <div class="container">
    <nav class="navbar navbar-default">
 <h1>KVS Digital - VOTING SYSTEM</h1>
    <ul class="nav navbar-nav">
      <li class="active"><a href="index.html">Home</a></li>
      <li><a href="login.html">Undian</a></li>
      <li><a href="admin.html">Admin</a></li>
    </ul>


  </nav>

<?php
      

$servername = "msv55-sh-ash";
    $username = "kvsdigit_nazli";
    $password="a0021856";
    $dbname = "kvsdigit_evote";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

else
{
if (isset($_POST['submit'])){
$var=$_POST["var1"];
$studentIC1=$_POST["studentIC"];
$studentName1=$_POST["studentName"];
$voteStatus1=$_POST["voteStatus"];

$update = "UPDATE tblstudent SET studentIC='$studentIC1',studentName='$studentName1',voteStatus='$voteStatus1' WHERE studentIC='$var'";
$query1 = mysqli_query($conn,$update);

if($query1){
    echo "Data berjaya dikemaskini";
}

}


if (isset($_POST['delete'])){
    $var=$_POST["var1"];
    echo "Adakah anda pasti untuk memadam data pelajar ini?";
   
    ?>
    <form action="update1.php" method="post">
        <input type="hidden" name="var2" value="<?=$var?>"/>
    <input type="submit" name="delete1" value="DELETE">
    <input type="button" onclick="location.href='search.html';" value="CANCEL">
    </form>
    
    <?php
}
if (isset($_POST['delete1'])){
    
         $ic = $_POST["var2"];
       
        $delete = "DELETE FROM tblstudent WHERE studentIC='$ic'";
        $query2 = mysqli_query($conn,$delete);
        if($query2){
        echo "<h3>data telah dipadamkan</h3>";
        }
        else
        echo "cuba lagi";
    }
   
}
 ?>
</div>
</body>
</html>