<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="css/bootstrap.min.css"/>
  <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>

  <title>Kolej Vokasional Sepang - E-Vote</title>
  <script type = "text/javascript" >
  history.pushState(null, null, 'index.html');
  window.addEventListener('popstate', function(event) {
  history.pushState(null, null, 'index.html');
  });

</script>
</head>
<body>

<div class="container">
<div class="container">
    <nav class="navbar navbar-default">

    <h1>KOLEJ VOKASIONAL SEPANG - E-VOTING SYSTEM</h1>
    <ul class="nav navbar-nav">
      <li class="active"><a href="index.html">Home</a></li>
      <li><a href="#">Profile Calon</a></li>
      <li><a href="#">Carian</a></li>
      <li><a href="loginregister.html">Undi</a></li>
      <li><a href="keputusan.php">Keputusan</a></li>
      <li><a href="loginregister.html">Login</a></li>
    </ul>

  </nav>

<?php
include_once "nav.php";
include 'dbconn.php';

$ic=$_POST["var1"];

if (isset($_POST['submit1'])) {
$sq = "UPDATE tblstudent SET voteStatus='1' WHERE studentIC=$ic";

$update = mysqli_query($conn,$sq);

// Loop to store and display values of individual checked checkbox.
foreach($_POST["check"] as $selected){
echo $selected."</br>";

$y=1;
while($y<=28){
  if($selected=="calon$y") {

        $votecast = "select * from tblcandidate where candID='$y'";
        $cast = mysqli_query($conn,$votecast);
        $row = mysqli_fetch_assoc($cast);
        
        $name1=$row["candName"];
        $count=$row["voteCount"];
        $count = $count + 1;
        $sq1 = "UPDATE tblcandidate SET voteCount='$count' WHERE candID='$y'";
        $qq=mysqli_query($conn, $sq1);
         echo "You choose $name1<br>";
         }
      $y++;
}
}


}
?>
</div>
</body>
</html>
