Advertisement
wahyu_f14

simpan-berita

Aug 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.               // -------------------- SIMPAN BERITA --------------------
  3.               if (isset($_POST['simpan-berita'])) {
  4.                 $id_pengguna = $_SESSION['profil-id'];
  5.                 $judul       = $_POST['judul'];
  6.                 $isi         = $_POST['isi'];
  7.                 $label       = $_POST['label'];
  8.  
  9.                 $cek_judul = mysqli_query($db, "SELECT id FROM berita WHERE judul='$judul'");
  10.                 if (mysqli_num_rows($cek_judul) > 0) {
  11.                   echo "<script>alert('Judul sudah ada !')</script>";
  12.                 } else {
  13.                   if ($_FILES['gambar']['tmp_name'] != '') {
  14.                     $gambar         = $_FILES['gambar']['tmp_name'];
  15.                     $gambar_name    = $_FILES['gambar']['name'];
  16.                     $gambar_size    = $_FILES['gambar']['size'];
  17.                     if ($gambar_size > 1000000) {
  18.                       echo "<script>alert('Ukuran gambar terlalu besar !')</script>";
  19.                     } else {
  20.                       move_uploaded_file($gambar, 'gambar/'.$gambar_name); // simpan gambar
  21.                       $simpan_berita = mysqli_query($db, "INSERT INTO berita(id_pengguna, judul, isi, tgl, label, gambar, status) VALUES('$id_pengguna', '$judul', '$isi', NOW(), '$label', '$gambar_name', 'publish')");
  22.                     }
  23.                   } else {
  24.                     $simpan_berita = mysqli_query($db, "INSERT INTO berita(id_pengguna, judul, isi, tgl, label, gambar, status) VALUES('$id_pengguna', '$judul', '$isi', NOW(), '$label', '', 'publish')");
  25.                   }
  26.  
  27.                   if ($simpan_berita == true) {
  28.                     echo "<script>alert('Berita telah disimpan')</script>";
  29.                   } else {
  30.                     echo "<script>alert('Gagal menyimpan data. ".mysqli_error($db)."')</script>";
  31.                   }
  32.                 }
  33.               }
  34.               ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement