DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.php

35 lines
1.0 KiB
PHP
Raw Permalink Normal View History

<?php
session_start();
require_once 'config.php';
header('Content-Type: application/json');
if (isset($_SESSION["username"]) && isset($_SESSION["admin"]))
{
$conn = dbConn();
$amount = $_POST["amount"];
$points = $_POST["points"];
$incident = $_POST["incident"];
$stmt = $conn->prepare("INSERT INTO Fines (Fine_amount, Fine_points, Incident_ID) VALUES (:amount, :points, :incident)");
$stmt->bindParam(":amount", $amount);
$stmt->bindParam(":points", $points);
$stmt->bindParam(":incident", $incident);
$stmt->execute();
$logSQL = "INSERT INTO Logs (Logs_type, Users_username, Logs_date) VALUES ('Added a fine', :username, NOW())";
$logStmt = $conn->prepare($logSQL);
$logStmt->bindParam(":username", $_SESSION["username"]);
$logStmt->execute();
echo json_encode(array("message" => "ok"));
}
else if (isset($_SESSION["username"]) && !isset($_SESSION["admin"]))
{
echo json_encode(array("message" => "not logged in as admin"));
}
else
{
echo json_encode(array("message" => "Not logged in "));
}
{
}