mercredi 21 septembre 2016

PHP Update Multiple Record based on checkbox

I have some problem with update multiple record... The case is I have a multiple field and record, and I want to update them in one process update and the update based on checkbox.. thanks

Here's my code

<?php require_once('../Connections/koneksi.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "index";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "admin";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frmdatapembayaran")) {

  $updateSQL = sprintf("UPDATE pembayaran SET periode=%s, tahunpelajaran=%s, nis=%s, jumlahharusbayar=%s, jumlahbayar=%s, tanggalbayar=%s, sumberdana=%s WHERE idpembayaran=%s",
                       GetSQLValueString($_POST['periode'], "date"),
                       GetSQLValueString($_POST['tahunpelajaran'], "text"),
                       GetSQLValueString($_POST['nis'], "text"),
                       GetSQLValueString($_POST['jumlahharusbayar'], "int"),
                       GetSQLValueString($_POST['jumlahbayar'], "int"),
                       GetSQLValueString($_POST['tanggalbayar'], "date"),
                       GetSQLValueString($_POST['sumberdana'], "text"),
                       GetSQLValueString($_POST['idpembayaran'], "int"));

  mysql_select_db($database_koneksi, $koneksi);
  $Result1 = mysql_query($query, $koneksi) or die(mysql_error());

  $updateGoTo = "pembayaran-spp.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$maxRows_rsSiswa = 8;
$pageNum_rsSiswa = 0;
if (isset($_GET['pageNum_rsSiswa'])) {
  $pageNum_rsSiswa = $_GET['pageNum_rsSiswa'];
}
$startRow_rsSiswa = $pageNum_rsSiswa * $maxRows_rsSiswa;

$colname_rsSiswa = "-1";
if (isset($_GET['nis'])) {
  $colname_rsSiswa = $_GET['nis'];
}
mysql_select_db($database_koneksi, $koneksi);
$query_rsSiswa = sprintf("SELECT * FROM siswa WHERE nis = %s", GetSQLValueString($colname_rsSiswa, "text"));
$query_limit_rsSiswa = sprintf("%s LIMIT %d, %d", $query_rsSiswa, $startRow_rsSiswa, $maxRows_rsSiswa);
$rsSiswa = mysql_query($query_limit_rsSiswa, $koneksi) or die(mysql_error());
$row_rsSiswa = mysql_fetch_assoc($rsSiswa);

if (isset($_GET['totalRows_rsSiswa'])) {
  $totalRows_rsSiswa = $_GET['totalRows_rsSiswa'];
} else {
  $all_rsSiswa = mysql_query($query_rsSiswa);
  $totalRows_rsSiswa = mysql_num_rows($all_rsSiswa);
}
$totalPages_rsSiswa = ceil($totalRows_rsSiswa/$maxRows_rsSiswa)-1;

$colname_rsKelas = "-1";
if (isset($_GET['idkelas'])) {
  $colname_rsKelas = $_GET['idkelas'];
}
mysql_select_db($database_koneksi, $koneksi);
$query_rsKelas = sprintf("SELECT kelas FROM kelas WHERE idkelas = %s", GetSQLValueString($colname_rsKelas, "int"));
$rsKelas = mysql_query($query_rsKelas, $koneksi) or die(mysql_error());
$row_rsKelas = mysql_fetch_assoc($rsKelas);
$totalRows_rsKelas = mysql_num_rows($rsKelas);

mysql_select_db($database_koneksi, $koneksi);
$query_Recordset1 = "SELECT * FROM `admin`";
$Recordset1 = mysql_query($query_Recordset1, $koneksi) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_rsJenisKelamin = "-1";
if (isset($_GET['idjeniskelamin'])) {
  $colname_rsJenisKelamin = $_GET['idjeniskelamin'];
}
mysql_select_db($database_koneksi, $koneksi);
$query_rsJenisKelamin = sprintf("SELECT * FROM jeniskelamin WHERE idjeniskelamin = %s", GetSQLValueString($colname_rsJenisKelamin, "int"));
$rsJenisKelamin = mysql_query($query_rsJenisKelamin, $koneksi) or die(mysql_error());
$row_rsJenisKelamin = mysql_fetch_assoc($rsJenisKelamin);
$totalRows_rsJenisKelamin = mysql_num_rows($rsJenisKelamin);

$colname_rsKompetensiKeahlian = "-1";
if (isset($_GET['idkompetensikeahlian'])) {
  $colname_rsKompetensiKeahlian = $_GET['idkompetensikeahlian'];
}
mysql_select_db($database_koneksi, $koneksi);
$query_rsKompetensiKeahlian = sprintf("SELECT * FROM kompetensikeahlian WHERE idkompetensikeahlian = %s", GetSQLValueString($colname_rsKompetensiKeahlian, "int"));
$rsKompetensiKeahlian = mysql_query($query_rsKompetensiKeahlian, $koneksi) or die(mysql_error());
$row_rsKompetensiKeahlian = mysql_fetch_assoc($rsKompetensiKeahlian);
$totalRows_rsKompetensiKeahlian = mysql_num_rows($rsKompetensiKeahlian);

$colname_rsPembayaran = "-1";
if (isset($_GET['nis'])) {
  $colname_rsPembayaran = $_GET['nis'];
}
mysql_select_db($database_koneksi, $koneksi);
$query_rsPembayaran = sprintf("SELECT * FROM pembayaran WHERE nis = %s", GetSQLValueString($colname_rsPembayaran, "text"));
$rsPembayaran = mysql_query($query_rsPembayaran, $koneksi) or die(mysql_error());
$row_rsPembayaran = mysql_fetch_assoc($rsPembayaran);
$totalRows_rsPembayaran = mysql_num_rows($rsPembayaran);

$colname_rsPembayaran2 = "-1";
if (isset($_GET['nis'])) {
  $colname_rsPembayaran2 = $_GET['nis'];
}
mysql_select_db($database_koneksi, $koneksi);
$query_rsPembayaran2 = sprintf("SELECT * FROM pembayaran WHERE nis = %s", GetSQLValueString($colname_rsPembayaran2, "text"));
$rsPembayaran2 = mysql_query($query_rsPembayaran2, $koneksi) or die(mysql_error());
$row_rsPembayaran2 = mysql_fetch_assoc($rsPembayaran2);
$totalRows_rsPembayaran2 = mysql_num_rows($rsPembayaran2);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pembayaran SPP <?php echo $row_rsSiswa['nama']; ?></title>
<script src="../js/jquery-1.11.2.min.js"></script>
<link href="../css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="../ao/datepicker/css/bootstrap-datepicker3.css"/>
</head>
<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
  <div class="navbar-header">

    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#defaultNavbar1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>

    <a class="navbar-brand" href="#"><!--<img style="max-width:28px; margin-top: -7px; float:inherit; margin-right: 10px;" src="../iouw.png"> !-->Admin Panel</a></div>

<div class="collapse navbar-collapse" id="defaultNavbar1">
      <ul class="nav navbar-nav">
        <li><a href="adm-panel.php">Home<span class="sr-only">(current)</span></a></li> 
        <li class="dropdown active"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">SPP<span class="caret"></span></a>
         <ul class="dropdown-menu" role="menu">
            <li><a href="tambah-tahun-ajaran">Tambah Tahun Ajaran</a></li>

            <li><a href="daftar-tahun-ajaran">Daftar Tahun Ajaran</a></li>
            <div class="divider"></div>
            <li><a href="setup-pembayaran-spp">Setup Pembayaran</a></li>
            <li><a href="setup-pembayaran-spp-siswa">Setup Pembayaran per Siswa</a></li>
            <div class="divider"></div>
            <li><a href="daftar-siswa">Pembayaran SPP Siswa</a></li>
            <div class="divider"></div>
            <li><a href="awal-rekap-spp">Rekap SPP Siswa</a></li>
        </ul>
        </li>
        <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Admin<span class="caret"></span></a>
         <ul class="dropdown-menu" role="menu">
        <li><a href="daftar-admin">Daftar Admin</a></li>
        <li><a href="tambah-admin">Tambah Admin</a></li>        
        </ul>
        </li>
                <li><a href="reset-database" id="deletetab">Reset Table (Pembayaran)</a></li>       
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="<?php echo $logoutAction ?>">Logout</a></li>
      </ul>
       <ul class="nav navbar-nav navbar-right">
        <form id="form1" name="form1" method="post" action="search.php" class="navbar-form" role="search">
        <div class="input-group">
            <input type="text" class="form-control" placeholder="Cari Nama" name="search" id="search">
            <div class="input-group-btn">
                <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
            </div>
        </div>
        </form>
    </ul>
<ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
      </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>



<div class="container-fluid">
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <h1 class="text-center">Pembayaran SPP</h1>
    </div>
  </div>
  <hr>
</div>
<div class="container">
  <div class="row">
<div class="col-md-10 col-md-offset-1">
    <fieldset>
                    <a href="daftar-siswa.php" type="button" class="btn btn-info">
                     <small><span class="glyphicon glyphicon-chevron-left"></span></small>
                    </a>
                <br />
      <hr>
      <h2 align="center"><strong>SISWA</strong></h2>
      <hr>
         <div id="legend">
             <img class="two" src="../upload/<?php echo $row_rsSiswa['file']; ?>" alt="..."/>
             <br>
             <br>
             <legend></legend>
         </div>

           <div class="row">
           <div class="col-sm-4">
                <label for="inputdefault">NIS (Nomor Induk Siswa)</label>
                <p><?php echo $row_rsSiswa['nis']; ?></p>
                <hr>
           </div>

           <div class="col-sm-4">
              <label for="inputdefault">Nama Lengkap</label>
              <p><?php echo $row_rsSiswa['nama']; ?></p>
              <hr>
            </div>  
           <div class="col-sm-4">
              <label for="inputdefault">Kelas & Jurusan</label>
              <p><?php echo $row_rsKelas['kelas']; ?></p>
              <hr>
            </div>  
           </div>

            <div class="row">

            <div class="col-sm-4">
              <label for="inputdefault">Tahun Masuk</label>
              <p><?php echo $row_rsSiswa['thnmasuk']; ?></p>
              <hr>
            </div>

            <div class="col-sm-4">
              <label for="inputdefault">Jenis Kelamin</label>
              <p><?php echo $row_rsJenisKelamin['jeniskelamin']; ?></p>
              <hr>
            </div>
            <div class="col-sm-4">
              <label for="inputdefault">Tanggal Lahir</label>
              <p><?php echo $row_rsSiswa['tgllahir']; ?></p>
              <hr>
            </div>


            </div>

            <div class="row">
            <div class="col-sm-4">
              <label for="inputdefault">Alamat Lengkap</label>
              <p><?php echo $row_rsSiswa['alamat']; ?></p>
              <hr>
            </div>
             <div class="col-sm-4">
              <label for="inputdefault">Nomor Telepon Orang Tua</label>
              <p><?php echo $row_rsSiswa['notelportu']; ?></p>
              <hr>
            </div>
            <div class="col-sm-4">
              <label for="inputdefault">Status</label>
              <p><?php echo $row_rsSiswa['status']; ?></p>
              <hr>
            </div>

            </div>

            <a href="detail-siswa.php?nis=<?php echo $row_rsSiswa['nis']; ?>&amp;idkelas=<?php echo $row_rsSiswa['idkelas']; ?>&amp;idjeniskelamin=<?php echo $row_rsSiswa['idjeniskelamin']; ?>&amp;idkompetensikeahlian=<?php echo $row_rsSiswa['idkompetensikeahlian']; ?>" class="btn btn-sm btn-primary">Detail</a>


      </div>

      <div class="col-md-10 col-md-offset-1">

            <br>
      <BR>
      <hr />
      <h2 align="center"><strong>SPP</strong></h2>
      <hr />
      <div class="row">
      <div class="col-sm-12" align="center">
      <h3 align="center"><strong>DATA PEMBAYARAN</strong></h3>
      <hr />
            <form action="<?php echo $editFormAction; ?>" method="POST" name="frmdatapembayaran" id="frmdatapembayaran">
      <table class="table table-striped table-bordered">
      <thead>
        <th class="hidden">ID</th>
        <th class="hidden">NIS</th>
                <th class="hidden">Tahun Ajaran</th>
        <th style="text-align:center">Periode</th>
        <th style="text-align:center">Jumlah Harus Bayar</th>
        <th style="text-align:center">Jumlah Bayar</th>
        <th style="text-align:center">Tanggal Pembayaran</th>
                <th style="text-align:center">Sumber Dana</th>
         <th style="text-align:center">Checkbox</th>

        </tr>
      </thead>
      <?php 
      $i=0;
      do { ?>
        <tbody>   

          <tr>
              <td class="hidden"><input type="text" name="idpembayaran[]" value="<?php echo $row_rsPembayaran['idpembayaran']; ?>" /></td>
               <td class="hidden"><input type="text" name="nis[]" value="<?php echo $row_rsPembayaran['nis']; ?>" /></td>
                              <td class="hidden"><input type="text" name="tahunpelajaran[]" value="<?php echo $row_rsPembayaran['tahunpelajaran']; ?>" /></td>
            <td class="col-md-2"><?php 
            $time=strtotime($row_rsPembayaran['periode']);
            $month=date("F",$time);
            $year=date("Y",$time);
            echo $month .','.' ', $year; ?>
            <input type="text" name="periode[]" class="hidden" value="<?php echo $row_rsPembayaran['periode']; ?>" /></td>
            <td class="col-md-2"><?php echo $row_rsPembayaran['jumlahharusbayar']; ?><input type="text" name="jumlahharusbayar[]" class="hidden" value="<?php echo $row_rsPembayaran['jumlahharusbayar']; ?>" /></td>
            <td class="col-md-2"><input class="form-control" id="jumlahbayar" type="text" required  name="jumlahbayar[]"  value="<?php echo $row_rsPembayaran['jumlahbayar']; ?>" /></td>
            <td class="col-md-2"><input type="text" class="form-control border-input tanggalbayar" name="tanggalbayar[]" id="tanggalbayar" value="<?php echo $row_rsPembayaran['tanggalbayar']; ?>" ></td>
            <td class="col-md-2"><input type="text" class="form-control border-input" name="sumberdana[]" id="sumberdana" value="<?php echo $row_rsPembayaran['sumberdana']; ?>" ></td>
            <td class="col-md-1" style="text-align:center"><input type="checkbox" name="id<?php echo $i; ?>" value="<?php echo $row_rsPembayaran['idpembayaran'] ?>"></td>



          </tr>

        </tbody>
        <?php 
        $i++;
        } while ($row_rsPembayaran = mysql_fetch_assoc($rsPembayaran)); ?>
      </table>
                              <button class="btn btn-success" type="submit" value="">Edit</button>
                              <input type="hidden" name="MM_update" value="frmdatapembayaran">
            </form>
      </div>
      </div>
      </div>




      </fieldset>
    </div>
  </div>
</div>




<br>
<br><br>
<br><br>
<br>

<footer class="footer">
      <div class="container">
<div class="footer.custom" style="color: #fff;">&copy; 2016 SMK TI Bali Global Singaraja</div>      </div>
</footer>
<script src="../js/bootstrap.js"></script>
<script src="../js/jquery-1.11.2.min.js"></script>
<script src="../ao/datepicker/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript">
            $(document).ready(function () {
                $('.tanggalbayar').datepicker({
                    format: "yyyy-mm-dd",
                    autoclose:true
                });
            });
</script>
<script language="JavaScript" type="text/javascript">
$(document).ready(function(){
    $("#deletetab").click(function(e){
        if(!confirm('Apakah Anda yakin ingin menghapus semua isi table?')){
            e.preventDefault();
            return false;
        }
        return true;
    });
});
</script>
</body>
</html>
<?php
mysql_free_result($rsSiswa);

mysql_free_result($rsKelas);

mysql_free_result($Recordset1);

mysql_free_result($rsJenisKelamin);

mysql_free_result($rsKompetensiKeahlian);

mysql_free_result($rsPembayaran);

mysql_free_result($rsPembayaran2);
?>




Aucun commentaire:

Enregistrer un commentaire