<?php
include "config_barcode.php"; 

echo '<br/>'.$postid = $_POST['postid'];
echo '<br/>'.$title = $_POST['title'];
echo '<br/>'.$content = $_POST['content'];
echo '<br/>'.$college_id=$_POST['college_id'];
echo '<br/>'.$course_name=$_POST['course_name'];
echo '<br/>'.$subject=$_POST['subject'];
echo '<br/>'.$college_type=$_POST['college_type'];
echo '<br/>'.$Course_Details=$_POST['Course_Details'];
echo '<br/>'.$day=$_POST['day'];
echo '<br/>'.$month=$_POST['month'];
echo '<br/>'.$year=$_POST['year'];
echo '<br/>'.$date=$day.'-'.$month.'-'.$year;
echo '<br/>'.$status='P';

// Check entry within table
$query = "SELECT * FROM att WHERE sid='$title' and date='$date' and subject='$subject' and session='$session' and code='$code'";

$result = mysqli_query($con,$query);
$fetchdata = mysqli_fetch_array($result);
$count = $fetchdata['sid'];
//echo $count.'----';
//$query2 = "SELECT * FROM class2 WHERE college='$college_id' and `CourseType`='$college_type' and `Course`='$course_name' and `Course_Details`='$Course_Details' and class_app LIKE '%$subject%' and college_roll='$title' order by id";

//$result2 = mysqli_query($con,$query2);
//$fetchdata2 = mysqli_fetch_array($result2);
//$count2 = $fetchdata2['college_roll'];
$queryr = "SELECT * FROM class2 WHERE college='$college_id' and `CourseType`='$college_type' and `Course`='$course_name' and `Course_Details`='$Course_Details' and college_roll='$title' and session='$session' and code='$code'";
$numresults=mysqli_query($con,$queryr);
$resultr = mysqli_query($con,$queryr) or die("Couldn't execute query1");
$a_row = mysqli_fetch_array( $resultr );
$count2 = $a_row['college_roll'];
$class_appp= $a_row['class_app'];


echo $count2.'/////////'.$class_appp;
if(($count=="")&&($count2!="")&&(stristr("$class_appp", "$subject"))){

//echo "**********";
    //$insertquery = "INSERT INTO posts(title,content) values('".$title."','".$content."')";
	$insertquery = "INSERT INTO att (sid,status,date,college_id,college_type,course_name,Course_Details,subject,code,session) VALUES ('".$title."','".$status."','".$date."','".$college_id."','".$college_type."','".$course_name."','".$Course_Details."','".$subject."','".$code."','".$session."')";
    mysqli_query($con,$insertquery);
    $postid = mysqli_insert_id($con);
}elseif(($count2!="")&&(stristr("$class_appp", "$subject"))) {
//echo "@@@@@@@@";
    //$updatequery = "UPDATE posts SET title='" . $title . "',content='".$content."' where id=" . $postid;
	$updatequery = "UPDATE att SET status='" . $status . "' where sid='$title' and date='$date' and subject='$subject'  and session='$session' and code='$code'";
	//$sql1="UPDATE att SET status='$status[$i]' WHERE id='$id[$i]'";
    mysqli_query($con,$updatequery);
}

echo $postid;  ?>

