Menu

Senin, 02 September 2019

Materi 10 tglskg.php

       <?php
         $tgl=date('j F Y');
         echo 'Tanggal Sekarang : ';
         echo $tgl;
       ?>

Materi 9 Membuat file skirpupdate.php Perintah Update

<?php
include "koneksi.php";
$id=$_POST['id'];
$nama=$_POST['nama'];
$alamat=$_POST['alamat'];
$tahun=$_POST['tahun'];
$kelas=$_POST['kelas'];
$rombel=$_POST['rombel'];



$sql = "update siswa set id='$id', nama='$nama',alamat='$alamat', tahun='$tahun', kelas='$kelas', rombel='$rombel' where id='$id'";
if(mysqli_query($dbconnect, $sql)){
    echo "Records were updated successfully.";
    echo "<script> location.replace('tampil.php'); </script>";
} else {
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($dbconnect);
}

// Close connection
mysqli_close($dbconnect);

?>

Materi 8 Membuat file update.php berupa formulir

<html>
<head>
            <title>Edit Data </title>
            <style type="text/css">
            .labelfrm{
                  display:block;
                  font-size:small;
                  margin-top:5px;
            }
            .error{
                  font-size:small;
                  color:red;
            }
            </style>
      </head>
      <body align="center">
       
<?php
include "menu.php";
?>
   
       


<?php
include "koneksi.php";
$id=$_GET['id'];
$query = mysqli_query($dbconnect, "SELECT * FROM siswa where id='$id'")
   or die (mysqli_error($dbconnect));
?>
<h1 alignment"center">EDIT DATA</h1>
<form action="skripupdate.php" method="post">
<table border="0" align="center">
<?php
while ($row = mysqli_fetch_array($query)){
?>
<input type="hidden" name="id" value="<?php echo "{$row['id']}";?>"/>
<tr>
<td>ID</td><td><input type="text" name="id" maxlength="3" size="3" value="<?php echo "{$row['id']}";?>" /></td>
</tr>
<tr>
<td>Nama</td><td><input type="text" name="nama" maxlength="25" size="25" value="<?php echo "{$row['nama']}";?>" /></td>
</tr>
<tr>
<td>Alamat</td><td><input type="text" name="alamat" maxlength="50" size="50" value="<?php echo "{$row['alamat']}";?>" /></td>
</tr>
<tr>
<td>tahun</td><td><input type="text" name="tahun" maxlength="4" size="4" value="<?php echo "{$row['tahun']}";?>" /></td>
</tr>
<tr>
<td>kelas</td><td><input type="text" name="kelas" maxlength="3" size="3" value="<?php echo "{$row['kelas']}";?>" /></td>
</tr>
<tr>
<td>rombel</td><td><input type="text" name="rombel" maxlength="1" size="1" value="<?php echo "{$row['rombel']}";?>" /></td>
</tr>

<tr><td></td><td align="center"><input type="submit" value="Simpan" name="simpan" /></td>
</tr>
<?php
}
?>
</table>
</form>
       <?php
            include "tglskg.php";
       ?>
</body>
</html>

Materi 7 Membuat file delete.php

<?php
                           
                           
include "koneksi.php";
$delete_id=$_GET['delete_id'];

echo "$delete_id";

$sql = "DELETE FROM siswa WHERE id=$delete_id";
if(mysqli_query($dbconnect, $sql)){
    echo "Records were deleted successfully.";
    echo "<script> location.replace('tampil.php'); </script>";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($dbconnect);
}

// Close connection
mysqli_close($dbconnect);

?>

Materi 6 membuat file menu.php

<table align="center" border="0">
    <tr>
        <td><a href="https://sulax.000webhostapp.com/latihan/entry.php"><img src="img/entry.png" height="50" width="50" /></a></td>
        <td><a href="https://sulax.000webhostapp.com/latihan/tampil.php"><img src="img/gambarsiswa.png" height="50" width="50" /></a></td>
    </tr>
    <tr>
        <td>ISI DATA</td>
        <td>TAMPIL</td>
    </tr>
</table>


--------------------
yang ditebali diganti dengan nama website kamu

Gambar silahkan download berikut :


Materi 5 Menambahkan include(menu.php) pada file tampil.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body align="center">

<?php
include "koneksi.php";

include "menu.php";

?>

<script type="text/javascript">
function delete_id(id)
{
     if(confirm('Yakin mau dihapus datanya ?'))
     {
        window.location.href='delete.php?delete_id='+id;
     }
}
</script>
   
<table border="1" cellpadding="5" cellspacing="0" align="center">
<tr>
  <td bgcolor='#000FFF'>Id</td>
  <td bgcolor='#000FFF'>Nama</td>
  <td bgcolor='#000FFF'>Alamat</td>
  <td bgcolor='#000FFF'>Tahun</td>
  <td bgcolor='#000FFF'>Kelas</td>
  <td bgcolor='#000FFF'>Rombel</td>
  <td bgcolor='#000FFF'>Delete</td>
  <td bgcolor='#000FFF'>Edit</td>
 

</tr>

   
   

<?php

$query = mysqli_query($dbconnect, "SELECT * FROM siswa order by id DESC")
   or die (mysqli_error($dbconnect));

//menampilkan JUMLAH BARIS
echo "<br>";
$jumlah=mysqli_num_rows($query);
echo "Jumlah data ada : ".$jumlah;
echo "<br><br>";
//SELESAI MENAMPILKAN JUMLAH

while ($row = mysqli_fetch_array($query)) {
  echo
   "<tr>
    <td align='center' bgcolor='#00FFFF'>{$row['id']}</td>
    <td bgcolor='#00FFFF'>{$row['nama']}</td>
    <td bgcolor='#00FFFF'>{$row['alamat']}</td>
    <td bgcolor='#00FFFF'>{$row['tahun']}</td>
    <td bgcolor='#00FFFF'>{$row['kelas']}</td>
    <td bgcolor='#00FFFF'>{$row['rombel']}</td>
    <td bgcolor='#00FFFF' align='center'><a href='javascript:delete_id($row[0])'>Delete</a></td>
    <td align='center' bgcolor='#00FFFF'><a href=update.php?id={$row['id']}/>Edit</a></td>
   </tr>\n";
}

?>
</table><br>
       <?php
            include "tglskg.php";
       ?>
</body>
<?
}
?>
</html>

Materi 4 : membuat file simpan.php

<?php
include "koneksi.php";
      $id = $_POST['id'];
      $nama = $_POST['nama'];
      $alamat = $_POST['alamat'];
      $tahun = $_POST['tahun'];
      $kelas = $_POST['kelas'];
      $rombel = $_POST['rombel'];
      $sql = "Insert Into siswa values('$id','$nama','$alamat','$tahun','$kelas','$rombel')";
if(mysqli_query($dbconnect, $sql)){
    echo "Records inserted successfully.";
     echo "<script> location.replace('tampil.php'); </script>";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($dbconnect);
}
// Close connection
mysqli_close($dbconnect);
?>

Materi ke 3 : memasukkan file entry.php

<html>
      <head>
            <title>HALAMAN ENTRY </title>
            <style type="text/css">
            .labelfrm{
                  display:block;
                  font-size:small;
                  margin-top:5px;
            }
            .error{
                  font-size:small;
                  color:red;
            }
            </style>
      </head>
      <body align="center">
       
<?php
// include "menu.php";
?>
   
            <h1>FORMULIR SIMPAN</h1>
 
            <form action="simpan.php" method="post" id="frm">
                <table align="center">
                  <tr>
                  <td><label for="id" class="labelfrm">ID : </label></td>
                  <td>
                      <input type="text" name="id" id="id" maxlength="3" class="required" size="3"
               
                    <?php
                        include "koneksi.php";
                        $query = mysqli_query($dbconnect, "SELECT max(id)+1 FROM siswa")
                        or die (mysqli_error($dbconnect));
                        while ($row = mysqli_fetch_array($query)){
                        ?>
                        value="<?php echo "{$row[0]}";?>"
                     
                        <?php
                        }
                    ?>
                  </td>
                  </tr>
                  <tr>
                  <td><label for="nama" class="labelfrm">Nama : </label></td>
                  <td><input type="text" name="nama" id="nama" maxlength="25" class="required" size="25"/></td>
                  </tr>
                  <tr>
                  <td><label for="alamat" class="labelfrm" >Alamat : </label></td>
                  <td><input type="text" name="alamat" id="alamat" size="50" class="required"/></td>
                  </tr>
                  <tr>
                  <td><label for="tahun" class="labelfrm">Tahun : </label></td>
                  <td>
                        <select name="tahun">
                          <option value="2019">2019</option>
                          <option value="2018">2018</option>
                          <option value="2017">2017</option>
                        </select>                   
                  </td>
                  </tr>
                  <tr>
                  <td><label for="kelas" class="labelfrm">Kelas : </label></td>
                  <td>
                        <select name="kelas">
                          <option value="TKR">TKR</option>
                          <option value="TB">TB</option>
                          <option value="TKJ">TKJ</option>
                        </select>
                  </td>
                  </tr>
                  <tr>
                  <td><label for="rombel" class="labelfrm">Rombel : </label></td>
                  <td>
                        <select name="rombel">
                          <option value="1">1</option>
                          <option value="2">2</option>
                          <option value="3">3</option>
                       
                        </select>
                   
                  </td>
               
               
                  </tr>
             
                  <tr>
                <td><input type="submit" name="input" value="Simpan" id="input"/></td>
                  <td><input type="reset" name="clear" value="clear" id="clear"/></td>
                  </table>
            </form>
      <br><br>
       
         
      </table>
      <br><br><br>

   
       <?php
         //   include "tglskg.php";
       ?>
       </body>
   
</html>