Advertisement
Guest User

data.siswa.save.php

a guest
Jul 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.58 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if($_SESSION['idPengguna'] && $_SESSION['id_level']){
  4.     if($_SESSION['id_level']=="1"){
  5.     include "./inc/conn.php";
  6.    
  7.     if(isset($_POST['simpan'])){
  8.    
  9.         $NIS=addslashes(htmlentities(ucwords($_POST['NIS'])));
  10.         $NISN=addslashes(htmlentities(ucwords($_POST['NISN'])));
  11.         $nama_siswa=addslashes(htmlentities(ucwords($_POST['nama_siswa'])));
  12.         $tmpt_lhr=addslashes(htmlentities(ucwords($_POST['tmpt_lhr'])));
  13.         $tgl_lhr=addslashes(htmlentities(ucwords($_POST['tgl_lhr'])));
  14.         $jns_kel=addslashes(htmlentities(ucwords($_POST['jns_kel'])));
  15.         $agama=addslashes(htmlentities(ucwords($_POST['agama'])));
  16.         $alamat_siswa=addslashes(htmlentities(ucwords($_POST['alamat_siswa'])));
  17.         $no_telp=addslashes(htmlentities(ucwords($_POST['no_telp'])));
  18.         $sekolah_asal=addslashes(htmlentities(ucwords($_POST['sekolah_asal'])));
  19.         $di_kelas=addslashes(htmlentities(ucwords($_POST['di_kelas'])));
  20.         $tgl_terima=addslashes(htmlentities(ucwords($_POST['tgl_terima'])));
  21.        
  22.         $password=md5($_POST['password']);
  23.         $nama_foto=$_FILES['foto']['name'];
  24.         $type = $_FILES['foto']['type'];
  25.         $ukuran=$_FILES['foto']['size'];
  26.        
  27.         if(empty($NIS) || empty($NISN) || empty($nama_siswa) || empty($tmpt_lhr) || empty($tgl_lhr) || empty($agama) ||empty($alamat_siswa) ||empty($no_telp) || empty($sekolah_asal) ||empty($password) || empty($nama_foto) ||empty($di_kelas) || empty($tgl_terima)){
  28.             $_SESSION['blengkap'] = '<p><div class="span12"><div class="alert alert-error"  style="margin-left:270px;margin-top:-10px;"><strong>Maaf, Form belum lengkap, silahkan ulangi kembali.</strong></div></div></p>';
  29.             echo "<script> document.location.href='home.php?page=data.siswa.tambah'; </script>";
  30.         }else{  
  31.             $query_nis=mysql_query("select * from tbl_siswa where NIS='$NIS' OR NISN='$NISN'");
  32.             $cek=mysql_num_rows($query_nis);
  33.             if($cek>0){
  34.                 $_SESSION['nis'] = '<p><div class="span12"><div class="alert alert-error" style="margin-left:270px;margin-top:-10px;"><strong>Maaf, NIS atau NISN sudah dipakai.</strong></div></div></p>';
  35.                 echo "<script> document.location.href='home.php?page=data.siswa.tambah'; </script>";
  36.             }else{
  37.                 if($type != "image/gif"  &&  $type != "image/jpg"  && $type != "image/jpeg" && $type != "image/png") {
  38.                     $_SESSION['file'] = '<p><div class="span12"><div class="alert alert-error"  style="margin-left:270px;margin-top:-10px;">File yang diizinkan hanya <strong>.jpg .jpeg .png dan .gif</strong>.</div></div></p>';
  39.                     echo "<script> document.location.href='home.php?page=data.siswa.tambah'; </script>";
  40.                 }else{
  41.                     if($ukuran>1000000){
  42.                         $_SESSION['ukuran'] = '<p><div class="span12"><div class="alert alert-error"  style="margin-left:270px;margin-top:-10px;">Maaf, ukuran file foto tidak lebih dari <strong>1MB</strong>.</div></div></p>';
  43.                         echo "<script> document.location.href='home.php?page=data.siswa.tambah'; </script>";
  44.                     }else{
  45.                         $uploaddir='./page/files/foto_siswa/';
  46.                         $rnd=date(His);            
  47.                         $nama_file_upload=$rnd.'-'.$nama_foto;
  48.                         $alamatfile=$uploaddir.$nama_file_upload;
  49.                        
  50.                         if (move_uploaded_file($_FILES['foto']['tmp_name'],$alamatfile))
  51.                         {
  52.                             $query=mysql_query("INSERT INTO tbl_siswa (NIS,NISN,nama_siswa,tmpt_lhr,tgl_lhr,jns_kel,agama,alamat_siswa,di_kelas,tgl_terima,no_telp,sekolah_asal,password,foto)
  53.                                         VALUES
  54. ('$NIS','$NISN','$nama_siswa','$tmpt_lhr',STR_TO_DATE('$tgl_lhr', '%d-%m-%Y'),'$jns_kel','$agama','$alamat_siswa','$di_kelas',STR_TO_DATE('$tgl_terima', '%d-%m-%Y'),'$no_telp','$sekolah_asal','$password','$nama_file_upload')");
  55.                                 $query2=mysql_query("INSERT INTO tbl_absensi (NIS) VALUES ('$NIS')");
  56.                             if($query && $query2){
  57.                                 $_SESSION['sukses'] = '<p><div class="span12"><div class="alert alert-success"  style="margin-left:270px; margin-top:-14px;"><strong>Data Anda berhasil disimpan.</strong> <a href="home.php?page=data.siswa" class="btn btn-success"><i class="icon-white icon-hand-left"></i> Lihat data siswa.</a></div></div></p>';
  58.                                 echo "<script> document.location.href='home.php?page=data.siswa.tambah'; </script>";
  59.                             }else{
  60.                                 echo mysql_error();
  61.                             }
  62.                         }else{
  63.                             $_SESSION['gagal'] = '<p><div class="span12"><div class="alert alert-error"  style="margin-left:270;pxmargin-top:-10px;">Proses upload gagal, <strong>periksa direktori</strong>. '.mysql_error().'</div></div></p>';
  64.                             echo "<script> document.location.href='home.php?page=data.siswa.tambah'; </script>";
  65.                         }
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.     }else{
  71.         unset($_POST['simpan']);
  72.     }
  73.  
  74. }else{
  75.                 echo '<p><div class="alert alert-error">Akses ditolak. Anda Bukan Admin.</div></p>';
  76.         }
  77.     }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement