Pharmacy Management System – Additional Code (Part 2)
📩 PHP – Contact Form Handler
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "support@pharmacy.com";
$subject = "Contact Form Message from $name";
$body = "From: $name
Email: $email
Message:
$message";
if (mail($to, $subject, $body)) {
echo "Message sent successfully.";
} else {
echo "Error sending message.";
}
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "support@pharmacy.com";
$subject = "Contact Form Message from $name";
$body = "From: $name
Email: $email
Message:
$message";
if (mail($to, $subject, $body)) {
echo "Message sent successfully.";
} else {
echo "Error sending message.";
}
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "support@pharmacy.com";
$subject = "Contact Form Message from $name";
$body = "From: $name
Email: $email
Message:
$message";
if (mail($to, $subject, $body)) {
echo "Message sent successfully.";
} else {
echo "Error sending message.";
}
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "support@pharmacy.com";
$subject = "Contact Form Message from $name";
$body = "From: $name
Email: $email
Message:
$message";
if (mail($to, $subject, $body)) {
echo "Message sent successfully.";
} else {
echo "Error sending message.";
}
}
?>
PHP – Pharmacist Login
<?php
session_start();
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM pharmacists WHERE username='$username'";
$result = $conn->query($sql);
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
$_SESSION['pharmacist_id'] = $user['id'];
header("Location: pharmacist_dashboard.php");
} else {
echo "Invalid credentials!";
}
}
?>
<?php
session_start();
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM pharmacists WHERE username='$username'";
$result = $conn->query($sql);
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
$_SESSION['pharmacist_id'] = $user['id'];
header("Location: pharmacist_dashboard.php");
} else {
echo "Invalid credentials!";
}
}
?>
<?php
session_start();
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM pharmacists WHERE username='$username'";
$result = $conn->query($sql);
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
$_SESSION['pharmacist_id'] = $user['id'];
header("Location: pharmacist_dashboard.php");
} else {
echo "Invalid credentials!";
}
}
?>
<?php
session_start();
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM pharmacists WHERE username='$username'";
$result = $conn->query($sql);
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
$_SESSION['pharmacist_id'] = $user['id'];
header("Location: pharmacist_dashboard.php");
} else {
echo "Invalid credentials!";
}
}
?>
📂 PHP – Download Invoice as PDF
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Invoice');
$pdf->Ln();
$pdf->SetFont('Arial','',12);
$pdf->Cell(100,10,'Customer: John Doe');
$pdf->Ln();
$pdf->Cell(100,10,'Date: ' . date('Y-m-d'));
$pdf->Ln();
$pdf->Output();
?>
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Invoice');
$pdf->Ln();
$pdf->SetFont('Arial','',12);
$pdf->Cell(100,10,'Customer: John Doe');
$pdf->Ln();
$pdf->Cell(100,10,'Date: ' . date('Y-m-d'));
$pdf->Ln();
$pdf->Output();
?>
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Invoice');
$pdf->Ln();
$pdf->SetFont('Arial','',12);
$pdf->Cell(100,10,'Customer: John Doe');
$pdf->Ln();
$pdf->Cell(100,10,'Date: ' . date('Y-m-d'));
$pdf->Ln();
$pdf->Output();
?>
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Invoice');
$pdf->Ln();
$pdf->SetFont('Arial','',12);
$pdf->Cell(100,10,'Customer: John Doe');
$pdf->Ln();
$pdf->Cell(100,10,'Date: ' . date('Y-m-d'));
$pdf->Ln();
$pdf->Output();
?>
📊 HTML – Google Charts Sales Overview
<html>
<head>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Sales'],
['Jan', 1000],
['Feb', 1170],
['Mar', 660],
['Apr', 1030]
]);
var options = { title: 'Monthly Sales', curveType: 'function',
legend: { position: 'bottom' } };
var chart = new
google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 600px; height: 300px"></div>
</body>
</html>
<html>
<head>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Sales'],
['Jan', 1000],
['Feb', 1170],
['Mar', 660],
['Apr', 1030]
]);
var options = { title: 'Monthly Sales', curveType: 'function',
legend: { position: 'bottom' } };
var chart = new
google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 600px; height: 300px"></div>
</body>
</html>
<html>
<head>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Sales'],
['Jan', 1000],
['Feb', 1170],
['Mar', 660],
['Apr', 1030]
]);
var options = { title: 'Monthly Sales', curveType: 'function',
legend: { position: 'bottom' } };
var chart = new
google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 600px; height: 300px"></div>
</body>
</html>
<html>
<head>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Sales'],
['Jan', 1000],
['Feb', 1170],
['Mar', 660],
['Apr', 1030]
]);
var options = { title: 'Monthly Sales', curveType: 'function',
legend: { position: 'bottom' } };
var chart = new
google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 600px; height: 300px"></div>
</body>
</html>
📦 SQL – Orders Table
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
total DECIMAL(10, 2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
total DECIMAL(10, 2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
total DECIMAL(10, 2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
total DECIMAL(10, 2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);