public static function fetchFromDb($id) { if (!is_numeric($id)) { return NULL; } $sql = "SELECT * FROM bsi_room_price 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("Database error: " . mysql_errno() . ". Message: " . mysql_error()); } if ($row = mysql_fetch_assoc($query)) { $roomPricePlan = RoomPricePlan::fetchFromParameters($row); mysql_free_result($query); return $roomPricePlan; } else { $this->setError("No room with id " . $id . " could be found."); mysql_free_result($query); return NULL; } }
<?php // TODO: Uncomment include "access.php"; include_once "../includes/SystemConfiguration.class.php"; global $systemConfiguration; global $logger; $errors = array(); $message = ""; $roomPricePlan = new RoomPricePlan(); if (isset($_POST['SBMT_REG'])) { $logger->LogInfo("Form has been submitted."); $roomPricePlan = RoomPricePlan::fetchFromParameters($_POST); if (!$roomPricePlan->save()) { $logger->LogError("Error saving room price plan."); foreach ($roomPricePlan->errors as $error) { $logger->LogError($error); $errors[] = $error; } } else { header("Location: room_price_list.php"); $message = "Values were updated successfully!"; } } else { if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $logger->LogInfo("Page was called for edit of id: " . $_REQUEST['id']); $id = intval($_REQUEST['id']); $logger->LogDebug("Numeric id is: {$id}"); $roomPricePlan = RoomPricePlan::fetchFromDb($id); if ($roomPricePlan == null) { $logger->LogError("Invalid request. No room price plan with id: {$id} exists.");