SHARE
TWEET

PHP 7 : Contoh Form Simpan 30 Juli 2018

stevennathaniel Jul 29th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4.  
  5.     <head>
  6.  
  7.         <title>Form Komputer</title>
  8.         <meta charset="utf-8">
  9.         <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  10.         <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
  11.         <meta name="viewport" content="width=device-width, initial-scale=1">
  12.         <script src="js/jquery-3.3.1.min.js"></script>
  13.         <link rel="stylesheet" href="css/bootstrap.min.css">
  14.         <script src="js/popper.min.js"></script>
  15.         <script src="js/bootstrap.min.js"></script>
  16.  
  17.     </head>
  18.  
  19.  
  20.     <body>
  21.  
  22.         <div class="container">
  23.  
  24.             <h2>Form Input Edit Hapus Data Komputer</h2>
  25.  
  26.             <form class="form-horizontal" role="form" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES); ?>">
  27.  
  28.                 <div class="form-group">
  29.  
  30.                     <label for="kodebarang">Kode Barang</label>
  31.                     <input type="text" class="form-control" id="kodebarang" name="kodebarang" placeholder="Masukan Kode Barang">
  32.  
  33.                 </div>
  34.  
  35.                 <div class="form-group">
  36.  
  37.                     <label for="hostname">Alamat Host</label>
  38.                     <input type="text" class="form-control" id="hostname" name="hostname" placeholder="Masukan Alamat Host">
  39.  
  40.                 </div>
  41.  
  42.                 <div class="form-group">
  43.  
  44.                     <label for="ipaddress">Alamat IP</label>
  45.                     <input type="text" class="form-control" id="ipaddress" name="ipaddress" placeholder="Masukan Alamat IP">
  46.  
  47.                 </div>
  48.  
  49.                 <div class="form-group">
  50.  
  51.                     <label for="macaddress">Alamat Mac</label>
  52.                     <input type="text" class="form-control" id="macaddress" name="macaddress" placeholder="Masukan Alamat Mac">
  53.  
  54.                 </div>
  55.  
  56.                 <button type="submit" class="btn btn-primary" name="tombolSimpan">Simpan</button>
  57.                 <button type="submit" class="btn btn-primary" name="tombolEdit">Edit</button>
  58.                 <button type="submit" class="btn btn-primary" name="tombolHapus">Hapus</button>
  59.             </form>
  60.  
  61.         </div>
  62.  
  63.     </body>
  64.  
  65. </html>
  66.  
  67.  
  68. <?php
  69.  
  70. if(isset($_POST["tombolSimpan"])) {
  71.  
  72.     $namaserver = "localhost";
  73.     $namapengguna = "root";
  74.     $password = "";
  75.     $namadatabase = "latihan";
  76.  
  77.     // Membuat Koneksi
  78.  
  79.     $koneksi = new mysqli($namaserver,$namapengguna,$password,$namadatabase);
  80.  
  81.     // Periksa Koneksi
  82.  
  83.     if($koneksi->connect_error) {
  84.  
  85.         die("Koneksi Gagal : " . $koneksi->connect_error);
  86.  
  87.  
  88.     }
  89.  
  90.     $sql = "INSERT INTO komputer(kodebarang,hostname,ipaddress,macaddress) Values ('".$_POST["kodebarang"]."','".$_POST["hostname"]."','".$_POST["ipaddress"]."','".$_POST["macaddress"]."')";
  91.  
  92.  
  93.  
  94.     if ($koneksi->query($sql) == TRUE) {
  95.  
  96.         echo "<script type='text/javascript'>alert('Data Berhasil Ditambahkan',window.open('file10.php','_self'));</script>";
  97.     } else {
  98.  
  99.         echo "<script type='text/javascript'>alert('Error: ".$sql."<br>".$koneksi->error."')</script>";
  100.  
  101.     }
  102.  
  103.     $koneksi->close();
  104.  
  105.     clearstatcache();
  106.  
  107. }
  108.  
  109.  
  110.  
  111.  
  112. ?>
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