public static function fetchFromDb($id) { ExtraService::$staticErrors = array(); if (!is_numeric($id)) { array_push(ExtraService::$staticErrors, "Id : {$id} is not numeric"); return null; } $sql = "SELECT * FROM bsi_extra_services WHERE id = {$id}"; $query = mysql_query($sql); if (!$query) { global $logger; $logger->LogFatal("Error executing query: {$sql}"); $logger->LogFatal("Database error: " . mysql_errno() . ". Message: " . mysql_error()); die("Error: " . mysql_error()); } if ($row = mysql_fetch_assoc($query)) { $extraService = ExtraService::fetchFromParameters($row); if ($extraService == null) { return null; } return $extraService; } else { array_push(ExtraService::$staticErrors, "No extra service with Id : {$id} exists"); return null; } }
<?php include "access.php"; include "../includes/SystemConfiguration.class.php"; global $logger; $extraService = new ExtraService(); $errors = array(); // If we have id, then we are trying to edit if (isset($_POST['SBMT_REG'])) { $extraService = ExtraService::fetchFromParameters($_POST); if (!$extraService->save()) { $errors = $extraService->errors; } else { header("Location: extra_services_list.php"); } } else { if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $extraService = ExtraService::fetchFromDb($id); if ($extraService == null) { $logger->LogError("Invalid request. No extra service with id: {$id} exists."); $errors[] = "Invalid request. No extra service with id: {$id} exists."; } } } include "header.php"; ?> </td>