<?php
session_start();

include 'dbconn.php';

//CHECK STUDENT STATUS

$studentIC = isset($_POST['studentIC']) ? trim($_POST['studentIC']) : '';

//check FOR IF STUDENT EXIST BASED ON IC

      $safeStudentIC = mysqli_real_escape_string($conn, $studentIC);
      $student = "SELECT * FROM tblstudent WHERE studentIC = '$safeStudentIC' LIMIT 1";
      $result1 = mysqli_query($conn, $student);
      
      if($result1 && mysqli_num_rows($result1) > 0){
      $row1 = mysqli_fetch_assoc($result1);


       $_SESSION["name"] = $row1["studentName"];
       $_SESSION["ic"] = $row1["studentIC"];
       //$count1=mysqli_num_rows($result1);
           if($row1["voteStatus"]==0){
            header("Location: profilpelajar.php");
            }
            else{
                header("Location: profilpelajar.php?error=Anda hanya boleh mengundi sekali sahaja");
            }
      }
      else
      {
        header("Location: profilpelajar.php?error=Sila masukkan no kad pengenalan yang betul");
      }
// {
//    
// header("Location: ../index.php?error=Sesi undian telah tamat");
// } 
// else if($row1["voteStatus"] == 1)
// {
//     header("Location: ../index.php?error=Anda hanya boleh mengundi sekali sahaja");
// }

// else
// {
//     header("Location: ../index.php?error=Sila masukkan no kad pengenalan yang betul");

?>