<?php
include 'includes/header.php';
include '../library/Services.php';
$services = new Services();
$getServiceByServiceId = $services->getServiceById($_GET['service_id']);
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit'])) {
$editServiceById = $services->editServiceById($_GET['service_id'], $_POST);
}
?>
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">BosCourier</a>
<ul class="navbar-nav px-3">
<li class="nav-item text-nowrap">
<a class="nav-link" href="#">Sign out</a>
</li>
</ul>
</nav>
<div class="container-fluid" style="">
<div class="row">
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
<span data-feather="home"></span>
Dashboard
<span class="sr-only">(current)</span>
</a>
</li>
</ul>
</div>
</nav>
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<h2>Edit <?= $getServiceByServiceId->name ?> </h2>
<form method="post">
<div class="form-group">
<label for="text"></label>
<textarea name="text" class="form-control" id="text" rows="3"><?= $getServiceByServiceId->text ?></textarea>
</div>
<input type="submit" name="edit" class="btn btn-secondary btn-lg mt-2" value="Edit" />
</form>
</main>
</div>
</div>
<?php include 'includes/footer.php'; ?>
<?php
include_once 'Session.php';
include 'Database.php';
class Services
{
private $db;
public function __construct()
{
$this->db = new Database();
}
/**
* @param $serviceId
* @param $data
* @return string
*/
public function editServiceById($serviceId, $data)
{
var_dump($serviceId);
die;
$sql = "UPDATE services set text = :text WHERE id = :id";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':text', $text);
$query->bindValue(':id', $serviceId);
$result = $query->execute();
if ($result) {
$message = "<div class='alert alert-success'>True</div>";
return $message;
} else {
$message = "<div class='alert alert-danger'><strong>False</strong></div>";
return $message;
}
}
/**
* @param $serviceId
* @return mixed
*/
public function getServiceById($serviceId){
$sql = "SELECT * FROM services WHERE id = :id LIMIT 1";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':id', $serviceId);
$query->execute();
$result = $query->fetch(PDO::FETCH_OBJ);
return $result;
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit'])) {
$editServiceById = $services->editServiceById($_GET['service_id'], $_POST);
}
// Display errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Log values
echo "<pre>";
var_dump($_SERVER['REQUEST_METHOD'], $_POST['edit'], isset($_POST['edit']));
echo "</pre>";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit'])) {
$editServiceById = $services->editServiceById($_GET['service_id'], $_POST);
}