Kamis, 10 November 2022

Upload file

Index

<?php 

include 'koneksi.php'; 

?>


<!DOCTYPE html>

<html>

<head>

<title>Data Siswa</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<div class="container">

<center>

<h2>Data Data Siswa</h2>

<?php 

if(isset($_GET['alert'])){

if($_GET['alert']=='gagal_ekstensi'){

?>

<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>

<h4><i></i> Peringatan !</h4>

Ekstensi Tidak Diperbolehkan

<?php

}elseif($_GET['alert']=="gagal_ukuran"){

?>

<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>

<h4><i></i> Peringatan !</h4>

Ukuran File terlalu Besar

<?php

}elseif($_GET['alert']=="berhasil"){

?>

<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>

<h4><i></i> Sukses</h4>

File Berhasil Disimpan

<?php

}

}

?>

<br>

<br>

<a href="tambah.php">Tambah Data</a>

<br>

<br>

<table border="3" cellpadding="7" class="table table-bordered">

<tr>

<th>Nama</th>

<th>Kelas</th>

<th>File</th>

                <th>status</th>

</tr>

<?php 

$data = mysqli_query($koneksi,"SELECT * FROM tbfile");

while($d = mysqli_fetch_array($data)){

?>

<tr>

<td><?php echo $d['nama']; ?></td>

<td><?php echo $d['kelas']; ?></td>

<td><?php echo $d['file']; ?></td>

<td>

                    <button><a href="hapus.php?id=<?= $d["id"]; ?>">Hapus</a></button>

<br>


<br>


<button><a href="aksi.php?id=<?= $d["id"]; ?>">Edit</a></button>



</td>

</tr>

<?php

}

 

?>

</table>

</center>

</body>

</html>



Koneksi

<?php 


$koneksi = mysqli_connect('localhost','root','','file');

    if (!$koneksi) {

        echo "Koneksi Gagal";

    

    }

    

    

        function hapus ($data) {

        global $koneksi;

        $id = $_GET['id'];

    

        $sql = mysqli_query($koneksi, "DELETE FROM tbfile WHERE id = '$id'");

    

        return mysqli_affected_rows($koneksi);

    

    }

    

       

 ?>



Tambahan

<!DOCTYPE html>

<html>

<head>

<title>Tambah File</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<style type="text/css">

table{

border-radius: 3%;

border: 3px solid;

border-color: black;

margin: 30px;

}

</style>

<body>

<center>

<table cellpadding="12">

<form action="aksi.php" method="post" enctype="multipart/form-data">

<tr>

<td colspan="2"><center><h2>Tambah Data Siswa</h2></center></td>

</tr>

<tr>

<td><label>Nama</label></td>

<td><input type="text" name="nama" required="required"></td>

</tr>

<tr>

<td><label>Kelas</label></td>

<td><input type="text" name="kelas" required="required"></td>

</tr>

<tr>

<td><label>File</label></td>

<td><input type="file" name="file" required="required"></td>

</tr>

<tr>

<td colspan="2"><p style="color: red">Ekstensi yang diperbolehkan .pdf | .docx | .doc | .pptx</p></td>

</tr>

<br>

<tr>

<td><input type="submit" name="submit" value="Simpan"></td>

<td><button><a href="index.php">Kembali</a></button></td>

</tr>

</form>

</table>

</center>

</body>

</html>



Aksi

<?php 


include 'koneksi.php';


$nama = $_POST['nama'];

$kelas = $_POST['kelas'];

 

$rand = rand();

$ekstensi =  array('pdf','docx','doc','pptx');

$filename = $_FILES['file']['name'];

$ukuran = $_FILES['file']['size'];

$ext = pathinfo($filename, PATHINFO_EXTENSION);

 

if(!in_array($ext,$ekstensi) ) {

header("location:index.php?alert=gagal_ekstensi");

}else{

if($ukuran < 1044070){

$xx = $rand.'_'.$filename;

move_uploaded_file($_FILES['file']['tmp_name'], 'file/'.$rand.'_'.$filename);

$simpan = mysqli_query($koneksi, "INSERT INTO tbfile VALUES('','$nama','$kelas','$xx')");

header("location:index.php?alert=berhasil");

if ($simpan) {

echo "<script>alert('File Berhasil Di Upload'); 

document.location.href='index.php</script>'";

}else{

echo "<script>alert('File Gagal Di Upload'); 

document.location.href='index.php</script>'";

}


}else{

header("location:index.php?alert=gagal_ukuran");

}

}


?>



Hapus

<?php 


require 'koneksi.php';


$id = $_GET['id'];


if( hapus($id) > 0 ) {


echo " Data Berhasil Di Hapus ";


} else {


echo " Data Tidak Berhasil Di Hapus ";


}


 ?>


 <br>


 <br>


 <button><a href="index.php">Kembali</a></button>

Kamis, 03 November 2022

Projek 4 update & delete

 Index

<!DOCTYPE html>


<html>


<head>


<title>Update Delete Projek 3</title>


</head>


<body>


<center>


<table border="2" cellpadding="10">


<tr>


<th>ID</th>


<th>Nama</th>


<th>Hobi</th>


<th>Aksi</th>


</tr>


<?php 


include 'koneksi.php';


$sql = mysqli_query($koneksi, "SELECT * FROM tugas4");




foreach ($sql as $data) {


?>


<tr>


<td><?php echo $data["id"];?></td>


<td><?php echo $data["nama"];?></td>


<td><?php echo $data["hobi"];?></td>


<td><a href="hapus.php?id=<?=$data["id"];?>">hapus</a>


<a href="edit.php?id=<?=$data["id"];?>">edit</a></td>


</tr>


<?php } ?>


</table></center>


</body>


</html>



Koneksi

<?php 


$koneksi = mysqli_connect("localhost","root", "", "keempat");




function hapus($data){


global $koneksi;




$id = $_GET['id'];




$sql = mysqli_query($koneksi, "DELETE FROM tugas4 WHERE id = '$id'");


return mysqli_affected_rows($koneksi);


}




function edit($data){


global $koneksi;



$id = $_GET['id'];


$nama = $_POST['nama'];

               $hobi = $row['hobi'];

$sql = "UPDATE tugas4 SET nama = '$_POST[nama]',

 hobi = '$_POST[hobi]' WHERE id ='$id'";


$query = mysqli_query($koneksi,$sql);


return mysqli_affected_rows($koneksi);


}


 ?>



Edit

<?php 

include "koneksi.php";

if(isset($_POST["submit"])) {

$id = $_POST['id']; 

$hobi  = implode(', ', $_POST['hobY']);

$sql = mysqli_query ($koneksi, "UPDATE tugas4 SET hobi = '$hobi' WHERE id = '$id' ");

header ('location:index.php?sukses');

}

$id = $_GET['id'];

$query_tampil = mysqli_query ($koneksi, "SELECT * FROM tugas4 WHERE id = '$id' ");

 

$edit = mysqli_fetch_array($query_tampil);


$checked = explode(', ', $edit['hobi']);


 

$query = mysqli_query($koneksi, "SELECT * FROM tugas4 ORDER BY id DESC");


?>

<style type="text/css">


    table{


        border-radius: 13%;


       border: 2px solid;


       border-color: black;


       margin: 30px;


    }


</style>


<form action="" method="post">

    

</form>


<html>


<head>


    <title>P4</title>


</head>


<style type="text/css">


    table{


        border-radius: 13%;


       border: 2px solid;


       border-color: black;


       margin: 30px;


    }


</style>


<body>


    <center>


    <form method="POST">


        

         <table cellpadding="13">


             <tr>


                 <th colspan="2"><h2>EDIT DATA</h2></th>


             </tr>


             <tr>


                 <td colspan="2"><input type="number" name="id" value="<?php echo $id; ?>" hidden></td>


             </tr>


             <tr>


                 <td><label>Nama</label>


                 <input type="text" name="nama" id="nama" value="<?php echo $edit["nama"];?>"></td>


             </tr>

             <tr>

                 <td><p>HOBI</p>


      <input type="checkbox" name="hobY[]" value="Bola" <?php in_array ('Bola', $checked) ? print "checked" : ""; ?> > Bola<br>

<input type="checkbox" name="hobY[]" value="Basket" <?php in_array ('Basket', $checked) ? print "checked" : ""; ?> >Basket<br>

<input type="checkbox" name="hobY[]" value="Berenang" <?php in_array ('Berenang', $checked) ? print "checked" : ""; ?> >Berenang<br>

<input type="hidden" name="id" value="<?php echo $edit["id"]?>"/>


      </td>

             </tr>


            

    

  </select>

             <tr>


                 <td colspan="2"><input type="submit" name="submit"></td>


             </tr>


         </table>


        


    </form>


    </center>


</body>


</html>



Hapus

<?php 


include 'koneksi.php';


$id = $_GET['id'];


if (hapus($id)>0) {


echo "


<script>alert('data berhasil dihapus');


document.location.href = 'index.php';


</script>";


}else{


echo "


<script>alert('data gagal dihapus');


</script>";


}


 ?>






Projek 3 update & delete

 Index

<!DOCTYPE html>


<html>


<head>


<title>Update Delete Projek 3</title>


</head>


<body>


<center>


<table border="2" cellpadding="10">


<tr>


<th>ID</th>


<th>Nama</th>


<th>Jenis Kelamin</th>


<th>Aksi</th>


</tr>


<?php 


include 'koneksi.php';


$sql = mysqli_query($koneksi, "SELECT * FROM tugas3");




foreach ($sql as $data) {


?>


<tr>


<td><?php echo $data["id"];?></td>


<td><?php echo $data["nama"];?></td>


<td><?php echo $data["jenkel"];?></td>


<td><a href="hapus.php?id=<?=$data["id"];?>">hapus</a>


<a href="edit.php?id=<?=$data["id"];?>">edit</a></td>


</tr>


<?php } ?>


</table></center>


</body>


</html>


Koneksi

<?php 


$koneksi = mysqli_connect("localhost","root", "", "ketiga");




function hapus($data){


global $koneksi;




$id = $_GET['id'];




$sql = mysqli_query($koneksi, "DELETE FROM tugas3 WHERE id = '$id'");


return mysqli_affected_rows($koneksi);


}




function edit($data){


global $koneksi;




$id = $_GET['id'];


$nama = $_POST['nama'];


$jenkel = $_POST['jenkel'];




$sql = "UPDATE tugas3 SET nama = '$nama', jenkel = '$jenkel' WHERE id ='$id'";


$query = mysqli_query($koneksi,$sql);


return mysqli_affected_rows($koneksi);


}


 ?>



Edit 

<?php 


include 'koneksi.php';




$id = $_GET['id'];




if (isset($_POST['submit'])) {


if (edit($_POST)>0) {


echo "<script>alert('data berhasil diedit');


document.location.href = 'index.php';


</script>";


}else{


echo "<script>alert('data gagal diedit');


</script>";


}


}


 ?>


 <!DOCTYPE html>


 <html>


 <head>


  <title></title>


 </head>


 <style type="text/css">


  table{


  border-radius: 13%;


border: 2px solid;


border-color: black;


margin: 30px;


  }


 </style>


 <body>


  <center>


  <form method="POST">


  <?php 


  $sql = mysqli_query($koneksi,"SELECT * FROM tugas3 WHERE id = '$id'");


  foreach ($sql as $row) {


  ?>


  <table cellpadding="13">


  <tr>


  <th colspan="2"><h2>EDIT DATA</h2></th>


  </tr>


  <tr>


  <td colspan="2"><input type="number" name="id" value="<?php echo $id; ?>" hidden></td>


  </tr>


  <tr>


  <td><label>Nama</label></td>


  <td><input type="text" name="nama" id="nama" value="<?php echo $row["nama"];?>"></td>


  </tr>


  <tr>


  <td><label>Jenis Kelamin</label></td>


  <td><?php  


  $jenkel = $row['jenkel'];




  if ($jenkel == "Laki-laki") {


  echo '<input type="radio" name="jenkel" value="Laki-laki" checked>Laki-laki


    <input type="radio" name="jenkel" value="Perempuan">Perempuan';


  }elseif ($jenkel == "Perempuan") {


  echo '<input type="radio" name="jenkel" value="Perempuan" checked>Perempuan


    <input type="radio" name="jenkel" value="Laki-laki">Laki-laki';


  }


 


 


  ?></td>


  </tr>


  <tr>


  <td colspan="2"><input type="submit" name="submit"></td>


  </tr>


  </table>


  <?php } ?>


  </form>


  </center>


 </body>


 </html>


Hapus

<?php 


include 'koneksi.php';




$id = $_GET['id'];




if (hapus($id)>0) {


echo "


<script>alert('data berhasil dihapus');


document.location.href = 'index.php';


</script>";


}else{


echo "


<script>alert('data gagal dihapus');


</script>";


}


 ?>







Projek 2 update&delete

 Index

<!DOCTYPE html>


<html>


<head>


<title>projek2</title>


</head>


<body>


<center>


<table border="2" cellpadding="10">


<tr>


<th>ID</th>


<th>Nama</th>


<th>Kelas</th>


            <th>Reaksi</th>


</tr>


<?php 


include 'koneksi.php';


$sql = mysqli_query($koneksi, "SELECT * FROM praktik2");




foreach ($sql as $data) {


?>


<tr>


<td><?php echo $data["id"];?></td>


<td><?php echo $data["nama"];?></td>


            <td><?php echo $data["kelas"];?></td>


<td><a href="hapus.php?id=<?=$data["id"];?>">hapus</a>


<a href="edit.php?id=<?=$data["id"];?>">edit</a></td>


</tr>


<?php } ?>


</table></center>


</body>


</html>




Koneksi


<?php 


$koneksi = mysqli_connect("localhost","root", "", "projek2");




function hapus($data){


global $koneksi;




$id = $_GET['id'];




$sql = mysqli_query($koneksi, "DELETE FROM praktik2 WHERE id = '$id'");


return mysqli_affected_rows($koneksi);


}




function edit($data){


global $koneksi;



$id = $_GET['id'];


$nama = $_POST['nama'];


$sql = "UPDATE praktik2 SET nama = '$nama' WHERE id ='$id'";


$query = mysqli_query($koneksi,$sql);


return mysqli_affected_rows($koneksi);


}


 ?>



Edit

<?php 


include 'koneksi.php';


$id = $_GET['id'];


if (isset($_POST['submit'])) {


if (edit($_POST)>0) {


echo "<script>alert('data berhasil diedit');


document.location.href = 'index.php';


</script>";


}else{


echo "<script>alert('data gagal diedit');


</script>";


}


}


 ?>


<!DOCTYPE html>


<html>


<head>


    <title></title>


</head>


<style type="text/css">


    table{


        border-radius: 13%;


       border: 2px solid;


       border-color: black;


       margin: 30px;


    }


</style>


<body>


    <center>


    <form method="POST">


        <?php 


            $sql = mysqli_query($koneksi,"SELECT * FROM praktik2 WHERE id = '$id'");


            foreach ($sql as $row) {


         ?>


         <table cellpadding="13">


             <tr>


                 <th colspan="2"><h2>EDIT DATA</h2></th>


             </tr>


             <tr>


                 <td colspan="2"><input type="number" name="id" value="<?php echo $id; ?>" hidden></td>


             </tr>


             <tr>


                 <td><label>Nama</label></td>


                 <td><input type="text" name="nama" id="nama" value="<?php echo $row["nama"];?>"></td>


             </tr>


             <tr>


                 <td colspan="2"><input type="submit" name="submit"></td>


             </tr>


         </table>


        <?php } ?>


    </form>


    </center>


</body>


</html>





Hapus

<?php 


include 'koneksi.php';


$id = $_GET['id'];


if (hapus($id)>0) {


echo "


<script>alert('data berhasil dihapus');


document.location.href = 'index.php';


</script>";


}else{


echo "


<script>alert('data gagal dihapus');


</script>";


}


 ?>







Projek 1 update dan delete

 Index

<!DOCTYPE html>


<html>


<head>


<title>Update Delete</title>


</head>


<body>


<center>


<table border="2" cellpadding="10">


<tr>


<th>ID</th>


<th>Nama</th>


<th>Reaksi</th>


</tr>


<?php 


include 'koneksi.php';


$sql = mysqli_query($koneksi, "SELECT * FROM tb_praktik1");




foreach ($sql as $data) {


?>


<tr>


<td><?php echo $data["id"];?></td>


<td><?php echo $data["nama"];?></td>


<td><a href="hapus.php?id=<?=$data["id"];?>">hapus</a>


<a href="edit.php?id=<?=$data["id"];?>">edit</a></td>


</tr>


<?php } ?>


</table></center>


</body>


</html>





Koneksi

<?php 


$koneksi = mysqli_connect("localhost","root", "", "projek1");




function hapus($data){


global $koneksi;




$id = $_GET['id'];




$sql = mysqli_query($koneksi, "DELETE FROM tb_praktik1 WHERE id = '$id'");


return mysqli_affected_rows($koneksi);


}




function edit($data){


global $koneksi;



$id = $_GET['id'];


$nama = $_POST['nama'];


$sql = "UPDATE tb_praktik1 SET nama = '$nama' WHERE id ='$id'";


$query = mysqli_query($koneksi,$sql);


return mysqli_affected_rows($koneksi);


}


 ?>






Edit

<?php 


include 'koneksi.php';


$id = $_GET['id'];


if (isset($_POST['submit'])) {


if (edit($_POST)>0) {


echo "<script>alert('data berhasil diedit');


document.location.href = 'index.php';


</script>";


}else{


echo "<script>alert('data gagal diedit');


</script>";


}


}


 ?>


<!DOCTYPE html>


<html>


<head>


    <title></title>


</head>


<style type="text/css">


    table{


        border-radius: 13%;


       border: 2px solid;


       border-color: black;


       margin: 30px;


    }


</style>


<body>


    <center>


    <form method="POST">


        <?php 


            $sql = mysqli_query($koneksi,"SELECT * FROM tb_praktik1 WHERE id = '$id'");


            foreach ($sql as $row) {


         ?>


         <table cellpadding="13">


             <tr>


                 <th colspan="2"><h2>EDIT DATA</h2></th>


             </tr>


             <tr>


                 <td colspan="2"><input type="number" name="id" value="<?php echo $id; ?>" hidden></td>


             </tr>


             <tr>


                 <td><label>Nama</label></td>


                 <td><input type="text" name="nama" id="nama" value="<?php echo $row["nama"];?>"></td>


             </tr>


             <tr>


                 <td colspan="2"><input type="submit" name="submit"></td>


             </tr>


         </table>


        <?php } ?>


    </form>


    </center>


</body>


</html>






Hapus

<?php 


include 'koneksi.php';


$id = $_GET['id'];


if (hapus($id)>0) {


echo "


<script>alert('data berhasil dihapus');


document.location.href = 'index.php';


</script>";


}else{


echo "


<script>alert('data gagal dihapus');


</script>";


}


 ?>