How to develop Projects (AstrologyMS)Using PHP and Mysql Part 10

Rashmi Mishra
4 minute read
0




How to develop Projects Using PHP and Mysql 

Part 10

 🔮 Astrology Management System

Module 2: Contact Astrologer (User Module)

Purpose:
Allows users to contact astrologers for consultations by submitting their personal details and concerns.


Functionalities:

Submit a contact request to an astrologer
View list of contact requests (for admin or astrologer)
Delete contact requests (if needed)


Project Structure:

Functionalities:

Users can submit a contact request to an astrologer with a message and preferred date/time
Admins/Astrologers can view all contact requests
Admins/Astrologers can update the status (Pending, Approved, Rejected)
Admins/Astrologers can send a reply message to the user
Admins can delete unnecessary contact requests


Project Structure:

/contact_astrologer/

── contact_form.php           # User contact form

── contact_list.php           # Admin/astrologer view of all requests

── update_status.php          # Update status or reply

── delete_contact.php         # Delete a contact request


Database Table:

CREATE TABLE contact_requests (

    id INT AUTO_INCREMENT PRIMARY KEY,

    name VARCHAR(255) NOT NULL,

    email VARCHAR(255) NOT NULL,

    contact VARCHAR(15),

    astrologer_id INT,

    preferred_date DATE,

    preferred_time TIME,

    message TEXT,

    status ENUM('Pending', 'Approved', 'Rejected') DEFAULT 'Pending',

    reply TEXT,

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (astrologer_id) REFERENCES astrologers(id)

);


contact_form.php – Submit a Contact Request (User Side)

<?php

// Start session

session_start();

 

// Include DB connection

include '../config/db_connect.php';

 

// Handle form submission

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $name           = mysqli_real_escape_string($conn, $_POST['name']);

    $email          = mysqli_real_escape_string($conn, $_POST['email']);

    $contact        = mysqli_real_escape_string($conn, $_POST['contact']);

    $astrologer_id  = (int)$_POST['astrologer_id'];

    $preferred_date = $_POST['preferred_date'];

    $preferred_time = $_POST['preferred_time'];

    $message        = mysqli_real_escape_string($conn, $_POST['message']);

 

    $sql = "INSERT INTO contact_requests (name, email, contact, astrologer_id, preferred_date, preferred_time, message)

            VALUES ('$name', '$email', '$contact', '$astrologer_id', '$preferred_date', '$preferred_time', '$message')";

 

    if (mysqli_query($conn, $sql)) {

        $success = " Your request has been submitted!";

    } else {

        $error = " Something went wrong: " . mysqli_error($conn);

    }

}

 

// Fetch astrologers (for dropdown)

$astrologers = mysqli_query($conn, "SELECT id, name FROM astrologers");

?>

 

<!DOCTYPE html>

<html>

<head>

    <title>Contact Astrologer</title>

    <style>

        body { font-family: Arial; background: #f0f2f5; padding: 20px; }

        .form-container {

            background: #fff;

            max-width: 600px;

            margin: auto;

            padding: 30px;

            border-radius: 10px;

            box-shadow: 0 0 8px #ccc;

        }

        h2 { text-align: center; margin-bottom: 20px; }

        label { display: block; margin-top: 10px; }

        input, select, textarea {

            width: 100%; padding: 10px;

            margin-top: 5px; border: 1px solid #ccc; border-radius: 5px;

        }

        button {

            margin-top: 20px;

            width: 100%;

            padding: 12px;

            background-color: #007bff;

            color: #fff; border: none;

            border-radius: 5px; cursor: pointer;

        }

        .message { margin-top: 15px; padding: 10px; text-align: center; }

        .success { color: green; }

        .error { color: red; }

    </style>

</head>

<body>

 

<div class="form-container">

    <h2>Contact an Astrologer</h2>

 

    <?php if (!empty($success)) echo "<div class='message success'>$success</div>"; ?>

    <?php if (!empty($error)) echo "<div class='message error'>$error</div>"; ?>

 

    <form method="POST" action="">

        <label>Name:</label>

        <input type="text" name="name" required>

 

        <label>Email:</label>

        <input type="email" name="email" required>

 

        <label>Contact Number:</label>

        <input type="text" name="contact" required>

 

        <label>Select Astrologer:</label>

        <select name="astrologer_id" required>

            <option value="">-- Choose Astrologer --</option>

            <?php while ($row = mysqli_fetch_assoc($astrologers)) : ?>

                <option value="<?= $row['id'] ?>"><?= htmlspecialchars($row['name']) ?></option>

            <?php endwhile; ?>

        </select>

 

        <label>Preferred Date:</label>

        <input type="date" name="preferred_date" required>

 

        <label>Preferred Time:</label>

        <input type="time" name="preferred_time" required>

 

        <label>Your Message:</label>

        <textarea name="message" rows="5" required></textarea>

 

        <button type="submit">Submit Request</button>

    </form>

</div>

 

</body>

</html>


📦 What Next?

Would you like me to continue with:

  • contact_list.php – Admin or astrologer view of submitted contact requests?
  • update_status.php – For updating status and sending a reply?
  • delete_contact.php – For deleting unnecessary requests?

contact_list.php – View All Contact Requests (Admin/Astrologer)

<?php

// Start session

session_start();

 

// Include DB connection

include '../config/db_connect.php';

 

// Fetch all contact requests with astrologer name

$sql = "SELECT c.*, a.name AS astrologer_name

        FROM contact_requests c

        LEFT JOIN astrologers a ON c.astrologer_id = a.id

        ORDER BY c.created_at DESC";

 

$result = mysqli_query($conn, $sql);

?>

 

<!DOCTYPE html>

<html>

<head>

    <title>Contact Requests</title>

    <style>

        body { font-family: Arial; padding: 20px; background: #f9f9f9; }

        h2 { text-align: center; margin-bottom: 20px; }

        table {

            width: 100%; border-collapse: collapse; background: #fff;

            box-shadow: 0 0 10px #ccc; border-radius: 5px;

            overflow: hidden;

        }

        th, td {

            padding: 12px; text-align: left;

            border-bottom: 1px solid #ddd;

        }

        th {

            background-color: #007bff; color: white;

        }

        tr:hover { background-color: #f1f1f1; }

        .btn {

            padding: 6px 12px; text-decoration: none;

            background-color: #28a745; color: white;

            border-radius: 4px;

        }

        .btn.delete {

            background-color: #dc3545;

        }

    </style>

</head>

<body>

 

<h2>All Contact Requests</h2>

 

<table>

    <tr>

        <th>#</th>

        <th>Name</th>

        <th>Email</th>

        <th>Contact</th>

        <th>Astrologer</th>

        <th>Date/Time</th>

        <th>Status</th>

        <th>Reply</th>

        <th>Action</th>

    </tr>

 

    <?php if (mysqli_num_rows($result) > 0): $i = 1; ?>

        <?php while ($row = mysqli_fetch_assoc($result)): ?>

            <tr>

                <td><?= $i++ ?></td>

                <td><?= htmlspecialchars($row['name']) ?></td>

                <td><?= htmlspecialchars($row['email']) ?></td>

                <td><?= htmlspecialchars($row['contact']) ?></td>

                <td><?= htmlspecialchars($row['astrologer_name']) ?></td>

                <td><?= htmlspecialchars($row['preferred_date']) ?> @ <?= $row['preferred_time'] ?></td>

                <td><?= $row['status'] ?></td>

                <td><?= $row['reply'] ?? '-' ?></td>

                <td>

                    <a class="btn" href="update_status.php?id=<?= $row['id'] ?>">Update</a>

                    <a class="btn delete" href="delete_contact.php?id=<?= $row['id'] ?>" onclick="return confirm('Are you sure to delete?')">Delete</a>

                </td>

            </tr>

        <?php endwhile; ?>

    <?php else: ?>

        <tr><td colspan="9" style="text-align: center;">No contact requests found.</td></tr>

    <?php endif; ?>

</table>

 

</body>

</html>



update_status.php – Update Status or Reply to Contact Request

<?php

// Start session

session_start();

 

// Include DB connection

include '../config/db_connect.php';

 

$id = $_GET['id'] ?? 0;

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $status = $_POST['status'];

    $reply = $_POST['reply'];

 

    $update = "UPDATE contact_requests SET status = ?, reply = ? WHERE id = ?";

    $stmt = $conn->prepare($update);

    $stmt->bind_param("ssi", $status, $reply, $id);

 

    if ($stmt->execute()) {

        header("Location: contact_list.php?success=updated");

        exit();

    } else {

        echo "Error updating contact request.";

    }

}

 

// Fetch contact request data

$query = "SELECT * FROM contact_requests WHERE id = ?";

$stmt = $conn->prepare($query);

$stmt->bind_param("i", $id);

$stmt->execute();

$data = $stmt->get_result()->fetch_assoc();

?>

 

<!DOCTYPE html>

<html>

<head>

    <title>Update Contact Request</title>

    <style>

        body { font-family: Arial; padding: 20px; }

        form { max-width: 500px; margin: auto; background: #f1f1f1; padding: 20px; border-radius: 8px; }

        input, select, textarea {

            width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ccc; border-radius: 4px;

        }

        button {

            background-color: #007bff; color: white; padding: 10px 15px; border: none; border-radius: 4px;

        }

    </style>

</head>

<body>

 

<h2 style="text-align:center;">Update Contact Request</h2>

 

<form method="POST">

    <label>Status:</label>

    <select name="status" required>

        <option value="Pending" <?= $data['status'] == 'Pending' ? 'selected' : '' ?>>Pending</option>

        <option value="Approved" <?= $data['status'] == 'Approved' ? 'selected' : '' ?>>Approved</option>

        <option value="Rejected" <?= $data['status'] == 'Rejected' ? 'selected' : '' ?>>Rejected</option>

    </select>

 

    <label>Reply Message:</label>

    <textarea name="reply" rows="4"><?= htmlspecialchars($data['reply']) ?></textarea>

 

    <button type="submit">Update Request</button>

</form>

 

</body>

</html>


delete_contact.php – Delete Contact Request

<?php

// Start session

session_start();

 

// Include DB connection

include '../config/db_connect.php';

 

if (isset($_GET['id'])) {

    $id = $_GET['id'];

 

    // Prepare delete query

    $sql = "DELETE FROM contact_requests WHERE id = ?";

    $stmt = $conn->prepare($sql);

    $stmt->bind_param("i", $id);

 

    if ($stmt->execute()) {

        header("Location: contact_list.php?deleted=1");

        exit();

    } else {

        echo "Failed to delete the contact request.";

    }

} else {

    echo "Invalid request.";

}

?>


 

Post a Comment

0Comments

Post a Comment (0)