<?php
include('../../../dbconnection/dbconnection.php');

if(isset($_POST["btn_action"])){
if($_POST["btn_action"]==="Add"){
	$adm_no=$_POST["adm"];
	// ECHO $_POST["pg"];
	$sql=$connect->prepare("SELECT * FROM students WHERE adm='$adm_no'");
  $sql->execute();
 $count=COUNT($sql->fetchAll());
	if($count===0){
		
		$query = "
			INSERT INTO students (adm,fname,lname,parent,gender,dob,date,phone,email,country,county,approval,pass) 
			VALUES (:adm_no,:fname,:lname,:parent,:gender,:dob,:date,:phone,:email,:country,:county,:approval,:password)
			";
		$statement=$connect->prepare($query);
		$statement->execute(
			array(
				":adm_no"		=>	$adm_no, 
				":fname" 		=>	$_POST["fname"],
				":lname"		=>	$_POST["lname"], 
				":parent"		=>	$_POST["pg"], 
				":gender"		=>	$_POST["gender"],  
				":dob"			=>	$_POST["dob"], 
				":date"			=>	time(), 
				":phone"		=>	$_POST["pno"], 
				":email"		=>	$_POST["user_email"],
				":country" 		=>	$_POST["country"], 
				":county" 		=>	$_POST["county"], 
				":approval"		=>	"1", 
				":password"		=>	password_hash(12345,PASSWORD_DEFAULT)
			)
		);
		$result = $statement->fetchAll();
			if(count($result))
			{
				echo 'New Student Added';
			}
	
	}else{
		
		echo "Student Admision  Number Already Exists";
	}
}
}

?>