Edit data tidak terupdate padahal tidak muncul error dan berhasil.

Pada saat klik edit, tidak ada perubahan edit. padahal ada syntax jika berhasil kembali ke laman list-pemesanan. Dan saat di klik edit, langsung ke laman list-pemesanan tetapi tidak ada perubahan data.

form edit

<html>
<?php

include("config.php");

// kalau tidak ada id di query string
if( !isset($_GET['nomor_pesanan']) ){
    header('Location: List-Pemesanan.php');
}

//ambil id dari query string
$id = $_GET['nomor_pesanan'];
  error_reporting(E_ALL * E_WARNING || E_NOTICE);
// buat query untuk ambil data dari database
$sql =  "SELECT * FROM pemesanan WHERE nomor_pesanan='$id' ";
$query = mysqli_query($db, $sql);
$order = mysqli_fetch_array($query);

// jika data yang di-edit tidak ditemukan
if( mysqli_num_rows($query) < 1 ){
    die("data tidak ditemukan...");
}

?>
<head>
    <title>Home | Ina Cahya</title>
    <link rel="stylesheet" href="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

<?php
const Copyright="Peaceminusone x Ina &#169; 2020";
?>

<body>
<header>
    <div class="header">
    <img src="img/Header.jpg" style="width:100%; margin:0; position: relative; max-width: 100%">
    </div>

    <nav>
    <ul>
        <li><a href="Home.php">Home</a></li>
        <li><a href="AboutUs.php">About Us</a></li>
        <li><a href="form.php">Form Order</a></li>
        <li><a href="List-Pemesanan.php">List Pemesanan</a></li>
    </ul>
</nav>
</header>
<main>

<div class="Form">
    <h2 class="judul">Form Order | Peaceminusone x INA</h2><br>

    <form method="POST" action="proses_edit.php">
<input type="hidden" name="nomor_pesanan" value="<?php echo $order['nomor_pesanan'] ?>" />

        <label>Nama Pemesan</label><br>
        <input type="text" name="nama_pemesan" class="kolom"  placeholder="Masukkan Nama Anda" value="<?=$order[1] ?> "/><br><br>

        <label>Nomor Handphone (Whatsapp)</label><br>
        <input type="text" name="nomor_HP" class="kolom" placeholder="Masukkan Nomor Anda" value="<?=$order[2] ?> " /><br><br>

        <label>Email</label><br>
        <input type="text" name="email" class="kolom"  placeholder="Masukkan Email Anda " value="<?=$order[3] ?> "/><br><br>

        <label>Alamat</label><br>
        <textarea name="alamat" class="kolom" rows="7" placeholder="Masukkan Alamat Anda "><?=$order[4] ?></textarea><br><br>

        <label> Kategori Pesanan</label><br>
        <input type="checkbox" id="Magazine" name="kategori" value="Magazine">
        <label for="Magazine">Magazine</label><br>
        <input type="checkbox" id="Album" name="kategori" value="Album">
        <label for="Album">Album</label><br>
        <input type="checkbox" id="Goods" name="kategori" value="Goods">
        <label for="Goods">Goods</label><br><br>

        <label>Nama Barang Pesanan</label><br>
        <input type="text" name="nama_barang" class="kolom"  placeholder="Masukkan Barang Pesanan Anda" value="<?=$order[6] ?> "/><br><br>

        <label>Jumlah Pesanan</label><br>
        <input type="text" name="jumlah" class="kolom" value="<?=$order[7] ?> "/><br><br>

        <label>Catatan Pesanan</label><br>
        <textarea name="catatan" class="kolom" rows="4" placeholder="Masukkan Catatan Pesanan Anda "><?=$order[8] ?></textarea>
        <p>Jelaskan lebih detail mengenai pemesanan dan jumlah barang</p>

        <label> Pembayaran</label><br>
        <select class="kolom" name="pembayaran">
            <option value="GO-Pay">GO-Pay</option>
            <option value="OVO">OVO</option>
            <option value="Dana">Dana</option>
            <option value="TransferBank">Transfer Bank</option>
        </select><br><br>

        <input type="submit" name="edit" value="Edit Pesanan" class="tombol">
        </form>
</div>
</main>

<footer>
    <p><?php echo Copyright ?></p>

</footer>
</body>
</html>

proses-edit.php

<?php

include("config.php");

// cek apakah tombol simpan sudah diklik atau blum?
if(isset($_POST['edit'])){

    // ambil data dari formulir

$nopesan = $_POST['nomor_pesanan'];
 $nama = $_POST['nama_pemesan'];
 $nomor =$_POST['nomor_HP'];
 $email = $_POST['email'];
 $alamat = $_POST['alamat'];
 $kategori = $_POST['kategori'];
 $barang = $_POST['nama_barang'];
 $jumlah =$_POST['jumlah'];
 $note = $_POST['catatan'];
 $payment = $_POST['pembayaran'];

    // buat query update
    $sql = "UPDATE pemesanan SET nama_pemesan='$nama', nomor_HP='$nomor', email='$email', alamat='$alamat', kategori='$kategori', nama_barang='$barang', jumlah='$jumlah', catatan='$note', pembayaran='$payment' WHERE nomor_pesanan='$nopesan' ";
    $query = mysqli_query($db, $sql) or die(mysql_error());

    // apakah query update berhasil?
    if( $query ) {
        // kalau berhasil alihkan ke halaman list-pemesanan.php
        header('Location: list-pemesanan.php');
    } else {
        // kalau gagal tampilkan pesan
        die("Gagal menyimpan perubahan...");
    }

} else {
    die("Akses dilarang...");
}

?>
avatar inacahya
@inacahya

3 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

Tanggapan

edit pertanyaan kamu, taro kode di tag kode agar mudah dibaca, bukan di jawaban

2 Jawaban:

<div>&lt;?php<br><br>include("config.php");<br><br>// kalau tidak ada id di query string<br>if( !isset($_GET['nomor_pesanan']) ){<br>&nbsp; &nbsp; header('Location: List-Pemesanan.php');<br>}<br><br>//ambil id dari query string<br>$id = $_GET['nomor_pesanan'];<br>&nbsp; error_reporting(E_ALL * E_WARNING || E_NOTICE);<br>// buat query untuk ambil data dari database<br>$sql =&nbsp; "SELECT * FROM pemesanan WHERE nomor_pesanan='$id' ";<br>$query = mysqli_query($db, $sql);<br>$order = mysqli_fetch_array($query);<br><br>// jika data yang di-edit tidak ditemukan<br>if( mysqli_num_rows($query) &lt; 1 ){<br>&nbsp; &nbsp; die("data tidak ditemukan...");<br>}<br><br>?&gt;<br>&lt;head&gt;&nbsp;<br>&nbsp; &nbsp; &lt;title&gt;Home | Ina Cahya&lt;/title&gt;<br>&nbsp; &nbsp; &lt;link rel="stylesheet" href=""&gt;<br>&nbsp; &nbsp; &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;<br><br>&lt;?php<br>const Copyright="Peaceminusone x Ina &amp;#169; 2020";<br>?&gt;<br><br>&lt;body&gt;<br>&lt;header&gt;<br>&nbsp; &nbsp; &lt;div class="header"&gt;<br>&nbsp; &nbsp; &lt;img src="img/Header.jpg" style="width:100%; margin:0; position: relative; max-width: 100%"&gt;<br>&nbsp; &nbsp; &lt;/div&gt;<br><br>&nbsp; &nbsp; &lt;nav&gt;<br>&nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;&lt;a href="Home.php"&gt;Home&lt;/a&gt;&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;&lt;a href="AboutUs.php"&gt;About Us&lt;/a&gt;&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;&lt;a href="form.php"&gt;Form Order&lt;/a&gt;&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;&lt;a href="List-Pemesanan.php"&gt;List Pemesanan&lt;/a&gt;&lt;/li&gt;<br>&nbsp; &nbsp; &lt;/ul&gt;<br>&lt;/nav&gt;<br>&lt;/header&gt;<br>&lt;main&gt; &nbsp;<br><br>&lt;div class="Form"&gt;<br>&nbsp; &nbsp; &lt;h2 class="judul"&gt;Form Order | Peaceminusone x INA&lt;/h2&gt;&lt;br&gt;<br><br><br>&nbsp; &nbsp; &lt;form method="POST" action="proses_edit.php"&gt;<br>&lt;input type="hidden" name="nomor_pesanan" value="&lt;?php echo $order['nomor_pesanan'] ?&gt;" /&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Nama Pemesan&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" name="nama_pemesan" class="kolom"&nbsp; placeholder="Masukkan Nama Anda" value="&lt;?=$order[1] ?&gt; "/&gt;&lt;br&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Nomor Handphone (Whatsapp)&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" name="nomor_HP" class="kolom" placeholder="Masukkan Nomor Anda" value="&lt;?=$order[2] ?&gt; " /&gt;&lt;br&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Email&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" name="email" class="kolom"&nbsp; placeholder="Masukkan Email Anda " value="&lt;?=$order[3] ?&gt; "/&gt;&lt;br&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Alamat&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;textarea name="alamat" class="kolom" rows="7" placeholder="Masukkan Alamat Anda "&gt;&lt;?=$order[4] ?&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt; Kategori Pesanan&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="checkbox" id="Magazine" name="kategori" value="Magazine"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="Magazine"&gt;Magazine&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="checkbox" id="Album" name="kategori" value="Album"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="Album"&gt;Album&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="checkbox" id="Goods" name="kategori" value="Goods"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="Goods"&gt;Goods&lt;/label&gt;&lt;br&gt;&lt;br&gt;<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Nama Barang Pesanan&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" name="nama_barang" class="kolom"&nbsp; placeholder="Masukkan Barang Pesanan Anda" value="&lt;?=$order[6] ?&gt; "/&gt;&lt;br&gt;&lt;br&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Jumlah Pesanan&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" name="jumlah" class="kolom" value="&lt;?=$order[7] ?&gt; "/&gt;&lt;br&gt;&lt;br&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;Catatan Pesanan&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;textarea name="catatan" class="kolom" rows="4" placeholder="Masukkan Catatan Pesanan Anda "&gt;&lt;?=$order[8] ?&gt;&lt;/textarea&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;p&gt;Jelaskan lebih detail mengenai pemesanan dan jumlah barang&lt;/p&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt; Pembayaran&lt;/label&gt;&lt;br&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;select class="kolom" name="pembayaran"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="GO-Pay"&gt;GO-Pay&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="OVO"&gt;OVO&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="Dana"&gt;Dana&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="TransferBank"&gt;Transfer Bank&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;&lt;br&gt;&lt;br&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="submit" name="edit" value="Edit Pesanan" class="tombol"&gt;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br>&lt;/div&gt;<br>&lt;/main&gt;<br><br>&lt;footer&gt;<br>&nbsp; &nbsp; &lt;p&gt;&lt;?php echo Copyright ?&gt;&lt;/p&gt;<br><br>&lt;/footer&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</div>

avatar inacahya
@inacahya

3 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>&lt;?php<br><br>include("config.php");<br><br>// cek apakah tombol simpan sudah diklik atau blum?<br>if(isset($_POST['edit'])){<br><br>&nbsp; &nbsp; // ambil data dari formulir<br><br>$nopesan = $_POST['nomor_pesanan'];<br>&nbsp;$nama = $_POST['nama_pemesan'];<br>&nbsp;$nomor =$_POST['nomor_HP'];<br>&nbsp;$email = $_POST['email'];<br>&nbsp;$alamat = $_POST['alamat'];<br>&nbsp;$kategori = $_POST['kategori'];<br>&nbsp;$barang = $_POST['nama_barang'];<br>&nbsp;$jumlah =$_POST['jumlah'];<br>&nbsp;$note = $_POST['catatan'];<br>&nbsp;$payment = $_POST['pembayaran'];<br><br>&nbsp; &nbsp; // buat query update<br>&nbsp; &nbsp; $sql = "UPDATE pemesanan SET nama_pemesan='$nama', nomor_HP='$nomor', email='$email', alamat='$alamat', kategori='$kategori', nama_barang='$barang', jumlah='$jumlah', catatan='$note', pembayaran='$payment' WHERE nomor_pesanan='$nopesan' ";<br>&nbsp; &nbsp; $query = mysqli_query($db, $sql) or die(mysql_error());<br><br>&nbsp; &nbsp; // apakah query update berhasil?<br>&nbsp; &nbsp; if( $query ) {<br>&nbsp; &nbsp; &nbsp; &nbsp; // kalau berhasil alihkan ke halaman list-pemesanan.php<br>&nbsp; &nbsp; &nbsp; &nbsp; header('Location: list-pemesanan.php');<br>&nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; // kalau gagal tampilkan pesan<br>&nbsp; &nbsp; &nbsp; &nbsp; die("Gagal menyimpan perubahan...");<br>&nbsp; &nbsp; }<br><br><br>} else {<br>&nbsp; &nbsp; die("Akses dilarang...");<br>}<br><br>?&gt;</div>

avatar inacahya
@inacahya

3 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban