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

Rashmi Mishra
0

 

How to develop Projects(OSMS) Using PHP and Mysql 

Part 10


7️ Online Service Management System

 Module 2: Add Customer Requests

Purpose:
Allows users/customers to submit service requests and lets admins view them.

Functionalities:

  •  Submit new service request
  •  View list of service requests
  •  Update status (e.g., Pending, In Progress, Completed)

Project Structure:

│── /requests/

   ── add_request.php           # Submit new request

   ── request_list.php          # List all service requests

   ── update_request.php        # Update request status/details

Database Table:

CREATE TABLE service_requests (

    id INT AUTO_INCREMENT PRIMARY KEY,

    customer_name VARCHAR(255) NOT NULL,

    contact_email VARCHAR(255) NOT NULL,

    service_type VARCHAR(255),

    description TEXT,

    status VARCHAR(50) DEFAULT 'Pending',

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

);

requests/add_request.php

<?php

include '../db.php';

 

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

    $customer_name = $_POST['customer_name'];

    $contact_email = $_POST['contact_email'];

    $service_type  = $_POST['service_type'];

    $description   = $_POST['description'];

 

    $sql = "INSERT INTO service_requests (customer_name, contact_email, service_type, description)

            VALUES ('$customer_name', '$contact_email', '$service_type', '$description')";

 

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

        echo "Request submitted successfully!";

    } else {

        echo "Error: " . mysqli_error($conn);

    }

}

?>


requests/request_list.php

<?php

include '../db.php';

 

$sql = "SELECT * FROM service_requests ORDER BY created_at DESC";

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

 

echo "<h2>Service Requests</h2>";

echo "<table border='1'>

<tr>

    <th>ID</th>

    <th>Customer Name</th>

    <th>Email</th>

    <th>Service Type</th>

    <th>Description</th>

    <th>Status</th>

    <th>Created At</th>

</tr>";

 

while ($row = mysqli_fetch_assoc($result)) {

    echo "<tr>

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

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

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

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

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

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

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

    </tr>";

}

 

echo "</table>";

?>


requests/update_request.php

<?php

include '../db.php';

 

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

    $id     = $_POST['id'];

    $status = $_POST['status'];

 

    $sql = "UPDATE service_requests SET status='$status' WHERE id='$id'";

 

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

        echo "Request status updated successfully!";

    } else {

        echo "Error: " . mysqli_error($conn);

    }

}

?>


🧾 Sample HTML Forms (for testing)

Form for add_request.php

<form method="POST" action="add_request.php">

    <input type="text" name="customer_name" placeholder="Customer Name" required><br>

    <input type="email" name="contact_email" placeholder="Email" required><br>

    <input type="text" name="service_type" placeholder="Service Type"><br>

    <textarea name="description" placeholder="Description"></textarea><br>

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

</form>

✏️ Form for update_request.php

<form method="POST" action="update_request.php">

    <input type="number" name="id" placeholder="Request ID" required><br>

    <select name="status">

        <option value="Pending">Pending</option>

        <option value="In Progress">In Progress</option>

        <option value="Completed">Completed</option>

    </select><br>

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

</form>



/comments/add_comment.php

<?php

include '../db.php';

 

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

    $blog_id = $_POST['blog_id'];

    $user_id = $_POST['user_id'];

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

 

    $sql = "INSERT INTO comments (blog_id, user_id, comment)

            VALUES ('$blog_id', '$user_id', '$comment')";

 

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

        echo "Comment added successfully!";

    } else {

        echo "Error: " . mysqli_error($conn);

    }

}

?>


/comments/comment_list.php

<?php

include '../db.php';

 

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

    $blog_id = $_GET['blog_id'];

 

    $sql = "SELECT c.id, c.comment, c.created_at, u.name AS user_name

            FROM comments c

            JOIN users u ON c.user_id = u.id

            WHERE c.blog_id = '$blog_id'

            ORDER BY c.created_at DESC";

 

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

 

    echo "<h2>Comments</h2>";

    echo "<ul>";

    while ($row = mysqli_fetch_assoc($result)) {

        echo "<li><strong>{$row['user_name']}:</strong> {$row['comment']} <br><small>Posted on: {$row['created_at']}</small></li><hr>";

    }

    echo "</ul>";

} else {

    echo "Blog ID not provided.";

}

?>


/comments/delete_comment.php

<?php

include '../db.php';

 

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

    $comment_id = $_POST['comment_id'];

 

    $sql = "DELETE FROM comments WHERE id = '$comment_id'";

 

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

        echo "Comment deleted successfully!";

    } else {

        echo "Error: " . mysqli_error($conn);

    }

}

?>


Post a Comment

0Comments

Post a Comment (0)