SHARE
TWEET

PHP 7 Sudah Ada Tombol UPDATE

stevennathaniel Jul 24th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if(isset($_POST["tombolSimpan"])){
  4.  
  5.     $namaserver = "localhost";
  6.     $namapengguna = "root";
  7.     $password = "";
  8.     $namadatabase = "latihan";
  9.  
  10.  
  11.     // Membuat koneksi
  12.  
  13.     $koneksi = new mysqli($namaserver,$namapengguna,$password,$namadatabase);
  14.  
  15.     // Periksa Koneksi
  16.  
  17.     if ($koneksi->connect_error) {
  18.  
  19.         die("Koneksi Gagal: " . $koneksi->connect_error);
  20.  
  21.     }
  22.  
  23.     $sql = "INSERT INTO komputer(kodebarang,hostname,ipaddress,macaddress) VALUES ('".$_POST["kodebarang"]."','".$_POST["hostname"]."','".$_POST["ipaddress"]."','".$_POST["macaddress"]."')";
  24.  
  25.     if ($koneksi->query($sql) === TRUE){
  26.  
  27.         echo "<script type='text/javascript'>alert('Data Berhasil Ditambahkan');</script>";
  28.  
  29.     } else {
  30.  
  31.         echo "<script type='text/javascript'>alert('Error: ". $sql ."<br>".$koneksi->error." ')</script>";
  32.  
  33.     }
  34.  
  35.     $koneksi->close();
  36. }
  37.  
  38.  
  39.  
  40. if(isset($_POST["tombolUpdate"])) {
  41.  
  42.     $namaserver = "localhost";
  43.     $namapengguna = "root";
  44.     $password = "";
  45.     $namadatabase = "latihan";
  46.  
  47.     // Membuat koneksi
  48.  
  49.     $koneksi = new mysqli($namaserver,$namapengguna,$password,$namadatabase);
  50.  
  51.     // Periksa Koneksi
  52.  
  53.     if($koneksi->connect_error) {
  54.  
  55.         die("Koneksi Gagal : " . $koneksi->connect_error);
  56.     }
  57.  
  58.  
  59.  
  60. $sql = "UPDATE komputer SET hostname='".$_POST["kodebarang"]."',ipaddress='".$_POST["ipaddress"]."',macaddress='".$_POST["macaddress"]."' WHERE kodebarang='".$_POST["kodebarang"]."'";
  61.  
  62. if ($koneksi->query($sql) === TRUE) {
  63.  
  64.     echo "<script type='text/javascript'>alert('Data Berhasil Di Update');</script>";
  65.  
  66.  
  67. } else {
  68.  
  69.     echo "<script type='text/javascript'>alert('Error : ".$sql."<br>".$koneksi->error."')</script>";
  70. }
  71.  
  72. $koneksi->close();
  73.  
  74. }
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