<?php
session_start();
 
?>

<!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
include 'dbconn.php';

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

else
{

}

$studentName=$_POST["studentName"];
$studentIC=$_POST["studentIC"];
$studentClass=$_POST["studentClass"];
$q = "select * from tblstudent WHERE studentIC='$studentIC'";
$query = mysqli_query($conn,$q);
$rowcount=mysqli_num_rows($query);

if($rowcount == 0){
 
$query1   = "INSERT into tblstudent (studentIC, studentName, studentClass, voteStatus) VALUES('$studentIC','$studentName', '$studentClass', 0)";

$query=mysqli_query($conn,$query1);

        if($query){
            echo "<script>alert('Data pengundi telah berjaya dimasukkan ke database');
                    window.location.href='admin.php';  
                    </script>";
          
 
     // echo "<h3></h3>";
           }
}

else


{
    echo "<script>alert('Data gagal dimasukkan. Data pengundi telah sedia ada dalam database');
                    window.location.href='admin.php';  
                    </script>";
//echo "<h3>Data gagal dimasukkan. Data pengundi telah sedia ada dalam database</h3>";
 }
?>
</div>
</body>
</html>