How to develop Projects (AMS)-1 Using PHP and Mysql Part 11

Rashmi Mishra
0

How to develop Projects(AMS-1)

 Using PHP and Mysql 

Part 11

 

Module 3: 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_astrologer/contact_form.php

User contact form to reach astrologer.

<?php

$conn = new mysqli("localhost", "root", "", "astro_db");

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

    $name = $_POST['name'];

    $email = $_POST['email'];

    $contact = $_POST['contact'];

    $astrologer_id = $_POST['astrologer_id'];

    $preferred_date = $_POST['preferred_date'];

    $preferred_time = $_POST['preferred_time'];

    $message = $_POST['message'];

    $stmt = $conn->prepare("INSERT INTO contact_requests

        (name, email, contact, astrologer_id, preferred_date, preferred_time, message)

        VALUES (?, ?, ?, ?, ?, ?, ?)");

    $stmt->bind_param("sssisss", $name, $email, $contact, $astrologer_id, $preferred_date, $preferred_time, $message);

    $stmt->execute();

    echo "Your request has been submitted!";

}

?>

 <form method="POST">

    Name: <input type="text" name="name" required><br>

    Email: <input type="email" name="email" required><br>

    Contact Number: <input type="text" name="contact"><br>

    Astrologer ID: <input type="number" name="astrologer_id" required><br>

    Preferred Date: <input type="date" name="preferred_date"><br>

    Preferred Time: <input type="time" name="preferred_time"><br>

    Message: <textarea name="message" required></textarea><br>

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

</form>


📂 /contact_astrologer/contact_list.php

Admin or astrologer can view all requests.

<?php

$conn = new mysqli("localhost", "root", "", "astro_db");

$result = $conn->query("SELECT * FROM contact_requests ORDER BY created_at DESC");

echo "<h2>Contact Requests</h2><table border='1'>";

echo "<tr><th>Name</th><th>Email</th><th>Message</th><th>Status</th><th>Action</th></tr>";

 while ($row = $result->fetch_assoc()) {

    echo "<tr>

        <td>{$row['name']}</td>

        <td>{$row['email']}</td>

        <td>{$row['message']}</td>

        <td>{$row['status']}</td>

        <td>

            <a href='update_status.php?id={$row['id']}'>Update</a> |

            <a href='delete_contact.php?id={$row['id']}'>Delete</a>

        </td>

    </tr>";

}

echo "</table>";

?>


📂 /contact_astrologer/update_status.php

Admin/Astrologer updates status or sends reply.

<?php

$conn = new mysqli("localhost", "root", "", "astro_db");

$id = $_GET['id'];

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

    $status = $_POST['status'];

    $reply = $_POST['reply'];

    $stmt = $conn->prepare("UPDATE contact_requests SET status = ?, reply = ? WHERE id = ?");

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

    $stmt->execute();

    echo "Request updated!";

}

$result = $conn->query("SELECT * FROM contact_requests WHERE id = $id");

$row = $result->fetch_assoc();

?>

<h3>Update Contact Request</h3>

<form method="POST">

    Status:

    <select name="status">

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

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

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

    </select><br>

    Reply: <textarea name="reply"><?= $row['reply'] ?></textarea><br>

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

</form>


📂 /contact_astrologer/delete_contact.php

Admins can delete a request.

<?php

$conn = new mysqli("localhost", "root", "", "astro_db");

$id = $_GET['id'];

$stmt = $conn->prepare("DELETE FROM contact_requests WHERE id = ?");

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

$stmt->execute();

echo "Contact request deleted!";

?>


Summary Table

File

Purpose

contact_form.php

User submits contact request to astrologer

contact_list.php

Admin/Astrologer views all submitted requests

update_status.php

Admin/Astrologer updates status and sends reply

delete_contact.php

Admin deletes contact requests if needed


 


Post a Comment

0Comments

Post a Comment (0)