Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // -------------------- SIMPAN BERITA --------------------
- if (isset($_POST['simpan-berita'])) {
- $id_pengguna = $_SESSION['profil-id'];
- $judul = $_POST['judul'];
- $isi = $_POST['isi'];
- $label = $_POST['label'];
- $cek_judul = mysqli_query($db, "SELECT id FROM berita WHERE judul='$judul'");
- if (mysqli_num_rows($cek_judul) > 0) {
- echo "<script>alert('Judul sudah ada !')</script>";
- } else {
- if ($_FILES['gambar']['tmp_name'] != '') {
- $gambar = $_FILES['gambar']['tmp_name'];
- $gambar_name = $_FILES['gambar']['name'];
- $gambar_size = $_FILES['gambar']['size'];
- if ($gambar_size > 1000000) {
- echo "<script>alert('Ukuran gambar terlalu besar !')</script>";
- } else {
- move_uploaded_file($gambar, 'gambar/'.$gambar_name); // simpan gambar
- $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')");
- }
- } else {
- $simpan_berita = mysqli_query($db, "INSERT INTO berita(id_pengguna, judul, isi, tgl, label, gambar, status) VALUES('$id_pengguna', '$judul', '$isi', NOW(), '$label', '', 'publish')");
- }
- if ($simpan_berita == true) {
- echo "<script>alert('Berita telah disimpan')</script>";
- } else {
- echo "<script>alert('Gagal menyimpan data. ".mysqli_error($db)."')</script>";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement