fbpx

Write review

<!DOCTYPE html>
<html lang="ms">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ruang Komen & Ulasan</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 0;
            background-color: #f9f9f9;
            color: #333;
        }
        .container {
            width: 90%;
            max-width: 800px;
            margin: 20px auto;
            background: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            overflow: hidden;
        }
        .header {
            background: #007BFF;
            color: #fff;
            padding: 15px;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-size: 24px;
        }
        .form-section, .reviews-section {
            padding: 20px;
        }
        .form-section h2, .reviews-section h2 {
            margin-bottom: 10px;
        }
        .form-section form {
            display: grid;
            gap: 10px;
        }
        .form-section label {
            font-weight: bold;
        }
        .form-section input, .form-section textarea, .form-section button {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .form-section button {
            background: #007BFF;
            color: #fff;
            border: none;
            cursor: pointer;
        }
        .form-section button:hover {
            background: #0056b3;
        }
        .reviews-section .review {
            border-bottom: 1px solid #eee;
            padding: 10px 0;
        }
        .review:last-child {
            border-bottom: none;
        }
        .review .name {
            font-weight: bold;
        }
        .review .date {
            color: #666;
            font-size: 0.9em;
        }
        .review .stars {
            color: #FFD700;
            font-size: 1.2em;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- Header -->
        <div class="header">
            <h1>Ruang Komen & Ulasan</h1>
        </div>

        <!-- Form Section -->
        <div class="form-section">
            <h2>Kongsikan Pengalaman Anda</h2>
            <form id="review-form" method="POST" action="submit_review.php">
                <label for="name">Nama:</label>
                <input type="text" id="name" name="name" placeholder="Nama penuh anda" required>

                <label for="email">E-mel (pilihan):</label>
                <input type="email" id="email" name="email" placeholder="contoh@email.com">

                <label for="review">Ulasan:</label>
                <textarea id="review" name="review" rows="4" placeholder="Tulis ulasan anda di sini..." required></textarea>

                <label for="rating">Penilaian:</label>
                <select id="rating" name="rating" required>
                    <option value="">-- Pilih --</option>
                    <option value="1">⭐</option>
                    <option value="2">⭐⭐</option>
                    <option value="3">⭐⭐⭐</option>
                    <option value="4">⭐⭐⭐⭐</option>
                    <option value="5">⭐⭐⭐⭐⭐</option>
                </select>

                <button type="submit">Hantar Ulasan</button>
            </form>
        </div>

        <!-- Reviews Section -->
        <div class="reviews-section">
            <h2>Apa Kata Pelanggan Kami?</h2>
            <?php
            // Fetch reviews from the database
            $conn = new mysqli('localhost', 'username', 'password', 'database');

            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            }

            $sql = "SELECT name, date, stars, review FROM reviews ORDER BY date DESC";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
                    echo "<div class='review'>";
                    echo "<p class='name'>" . htmlspecialchars($row['name']) . "</p>";
                    echo "<p class='date'>" . htmlspecialchars($row['date']) . "</p>";
                    echo "<p class='stars'>" . str_repeat('⭐', $row['stars']) . "</p>";
                    echo "<p>" . htmlspecialchars($row['review']) . "</p>";
                    echo "</div>";
                }
            } else {
                echo "<p>Tiada ulasan lagi. Jadilah yang pertama untuk berkongsi pengalaman anda!</p>";
            }

            $conn->close();
            ?>
        </div>
    </div>
</body>
</html>