<?php
session_start();
include"../../../../inc/conn.php";

// CEK HAK AKSES DISINI


$id_kelas			= str_replace("'","`",(isset($_POST['id_kelas'])) ? $_POST['id_kelas'] : "");
$nama_lengkap		= str_replace("'","`",(isset($_POST['nama_lengkap'])) ? $_POST['nama_lengkap'] : "");
$username			= str_replace("'","`",(isset($_POST['username'])) ? $_POST['username'] : "");
$password			= str_replace("'","`",(isset($_POST['password'])) ? $_POST['password'] : "");

$cekakun=mysqli_query($connect,"select * from tb_siswa where username='".$username."'");
$jumakun=mysqli_num_rows($cekakun);

if($jumakun!=0){

	echo"<script>alert('Username telah digunakan !');history.go(-1)</script>";

}else{

	$simpan = mysqli_query($connect,"insert into tb_siswa set 

			id_kelas 			= '".$id_kelas."',
			nama_lengkap		= '".$nama_lengkap."',
			username 			= '".$username."',
			password 			= '".$password."'")or die(mysqli_error($connect));


	if($simpan){
		echo"<script>alert('Data berhasil disimpan !');</script>";
		echo"<script>document.location.href='index.php?prefix=datasiswa&kelas=$id_kelas'</script>";
	}else{
		echo"<script>alert('Gagal mengeksekusi perintah ini !');history.go(-1)</script>";
	}

}
?>