Add data IOM tidak ada respon ketika klik kirim, berikut kodingannya, dmn kira2 kendalnya..?

<?php // submit_iom.php include('db_connection.php'); include('auth.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = $_POST['title']; $content = $_POST['content']; $user_id = $_SESSION['user_id']; // Pengguna yang membuat IOM

 // Debug data POST dan sesi
//  var_dump($title, $content, $user_id);
 
// Simpan IOM ke database
$stmt = $pdo-&gt;prepare(&quot;INSERT INTO iom (title, content, created_by) VALUES (?, ?, ?)&quot;);
$stmt-&gt;execute([$title, $content, $user_id]);
// $iom_id = $pdo-&gt;lastInsertId();

// Set status IOM ke &#039;pending_approval&#039;
$stmt = $pdo-&gt;prepare(&quot;UPDATE iom SET status = &#039;pending_approval&#039; WHERE id = ?&quot;);
$stmt-&gt;execute([$iom_id]);

// Redirect ke halaman daftar IOM
header(&#039;Location: iom_list.php&#039;);
exit;

} ?>

<!DOCTYPE html> <html lang="en">

<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IOM</title> <link rel="stylesheet" href="assets/css/bootstrap.min.css"> </head>

<body> <div class="container mt-5"> <form method="POST"> <div class="mt-3"> <div class="form-group"> <label for="title">Judul IOM</label> <input type="text" class="form-control" id="title" name="title" required> </div> </div> <div class="mt-3"> <div class="form-group"> <label for="content">Isi IOM</label> <textarea id="content" name="content" required></textarea> </div> </div> <button type="submit" class="btn btn-primary mt-3">Kirim IOM</button> <button type="button" name="submit" onClick="write_wall_post();return false;">SEND</button> </form>

    &lt;script src=&quot;https://cdn.ckeditor.com/ckeditor5/36.0.1/classic/ckeditor.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
        ClassicEditor.create(document.querySelector(&#039;#content&#039;)).catch(error =&gt; {
            console.error(error);
        });
    &lt;/script&gt;
&lt;/div&gt;

</body>

</html>

dan berikut DB tabel nya.

CREATE TABLE iom (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    content TEXT NOT NULL,
    created_by INT NOT NULL,
    department_head_approval ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
    deputy_property_manager_approval ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
    property_manager_approval ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
    status ENUM('draft', 'pending_approval', 'approved', 'rejected') DEFAULT 'draft',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (created_by) REFERENCES users(id)
);

Berikut koneksi db nya.

<?php
// Informasi koneksi database
$host = 'localhost';      // Host database (default: localhost)
$dbname = 'iom3'; // Ganti dengan nama database Anda
$username = 'root';        // Ganti dengan username database Anda
$password = '';            // Ganti dengan password database Anda

try {
    // Membuat koneksi menggunakan PDO
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    // Atur PDO error mode menjadi Exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    // Tampilkan pesan error jika koneksi gagal
    die("Koneksi ke database gagal: " . $e->getMessage());
}
?>

avatar abysalfa
@abysalfa

1 Kontribusi 0 Poin

Dipost 3 hari yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban