SHARE
TWEET

Untitled

a guest Oct 13th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Simple CRUD by TUTORIALWEB.NET</title>
  5.     <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
  6. </head>
  7. <body>
  8.     <h2>My CRUD</h2>
  9.    
  10.     <div class="btn-group m-1" role="group" aria-label="Basic example">
  11.       <a type="button" href="index.php" class="btn btn-secondary">Beranda</a>
  12.       <a type="button" href="tambah.php" class="btn btn-secondary">Tambah Data</a>
  13.     </div>
  14.  
  15.    
  16.     <h3>Edit Data</h3>
  17.    
  18.     <?php
  19.     //proses mengambil data ke database untuk ditampilkan di form edit berdasarkan siswa_id yg didapatkan dari GET id -> edit.php?id=siswa_id
  20.    
  21.     //include atau memasukkan file koneksi ke database
  22.     include('koneksi.php');
  23.    
  24.     //membuat variabel $id yg nilainya adalah dari URL GET id -> edit.php?id=siswa_id
  25.     $id = $_GET['id'];
  26.    
  27.     //melakukan query ke database dg SELECT table siswa dengan kondisi WHERE siswa_id = '$id'
  28.     $show = mysqli_query($koneksi, "SELECT * FROM mydata WHERE Id='$id'");
  29.    
  30.     //cek apakah data dari hasil query ada atau tidak
  31.     if(mysqli_num_rows($show) == 0){
  32.        
  33.         //jika tidak ada data yg sesuai maka akan langsung di arahkan ke halaman depan atau beranda -> index.php
  34.         echo '<script>window.history.back()</script>';
  35.        
  36.     }else{
  37.    
  38.         //jika data ditemukan, maka membuat variabel $data
  39.         $data = mysqli_fetch_assoc($show);  //mengambil data ke database yang nantinya akan ditampilkan di form edit di bawah
  40.    
  41.     }
  42.     ?>
  43.    
  44.     <form action="edit-proses.php" method="post">
  45.         <input type="hidden" name="id" value="<?php echo $id; ?>">  <!-- membuat inputan hidden dan nilainya adalah siswa_id -->
  46.         <table cellpadding="3" cellspacing="0">
  47.             <tr>
  48.                 <td>Nama</td>
  49.                 <td>:</td>
  50.                 <td><input type="text" name="nama" value="<?php echo $data['Nama']; ?>" required/></td> <!-- value diambil dari hasil query -->
  51.             </tr>
  52.             <tr>
  53.                 <td>Username</td>
  54.                 <td>:</td>
  55.                 <td><input type="text" name="username" size="30" value="<?php echo $data['Username']; ?>" required/></td> <!-- value diambil dari hasil query -->
  56.             </tr>
  57.             <tr>
  58.                 <td>Password</td>
  59.                 <td>:</td>
  60.                 <td><input type="text" name="password" size="30" value="<?php echo $data['Password']; ?>" required/></td> <!-- value diambil dari hasil query -->
  61.             </tr>
  62.             <tr>
  63.                 <td>Email</td>
  64.                 <td>:</td>
  65.                 <td><input type="text" name="email" size="30" value="<?php echo $data['Email']; ?>" required/></td> <!-- value diambil dari hasil query -->
  66.             </tr>
  67.            
  68.             <tr>
  69.                 <td>&nbsp;</td>
  70.                 <td></td>
  71.                 <td><input type="submit" name="simpan" value="Simpan"/></td>
  72.             </tr>
  73.         </table>
  74.     </form>
  75.     <script type="text/javascript" src="css/bootstrap.min.js"></script>
  76. </body>
  77. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top