<?php // check if value was posted if ($_POST) { // include classes include_once '../config/database.php'; include_once '../objects/product.php'; include_once '../objects/product_image.php'; include_once '../objects/product_pdf.php'; // get database connection $database = new Database(); $db = $database->getConnection(); // initialize objects $product = new Product($db); $productImage = new ProductImage($db); $productPdf = new ProductPdf($db); // set product id to be deleted $product_id = $_POST['object_id']; // delete the product $product->id = $product_id; if ($product->delete()) { // delete all related images in database & directory $productImage->product_id = $product_id; $productImage->deleteAll(); // delete all related pdf in database & directory $productPdf->product_id = $product_id; $productPdf->deleteAll(); echo "Object was deleted."; } else { echo "Unable to delete object."; }
include_once "layout_head.php"; // read products button echo "<div class='right-button-margin'>"; echo "<a href='read_products.php' class='btn btn-primary pull-right'>"; echo "<span class='glyphicon glyphicon-list'></span> Read Products"; echo "</a>"; echo "</div>"; // if the form was submitted if ($_POST) { // instantiate product object include_once '../objects/product.php'; include_once '../objects/product_image.php'; include_once '../objects/product_pdf.php'; $product = new Product($db); $productImage = new ProductImage($db); $productPdf = new ProductPdf($db); // set product property values $product->name = $_POST['name']; $product->price = $_POST['price']; $product->description = $_POST['description']; $product->category_id = $_POST['category_id']; $product->active_until = $_POST['active_until']; // create the product if ($product->create()) { // get last inserted id $product_id = $db->lastInsertId(); // save the images $productImage->product_id = $product_id; $productImage->upload(); // save the pdf files $productPdf->product_id = $product_id;
<?php // check if value was posted if ($_POST) { // include classes include_once '../config/database.php'; include_once '../objects/product_pdf.php'; // get database connection $database = new Database(); $db = $database->getConnection(); // prepare product pdf object $product_pdf = new ProductPdf($db); // set product pdf id to be deleted $pdf_id = $_POST['object_id']; // delete the product pdf record $product_pdf->id = $pdf_id; if ($product_pdf->delete()) { echo "Object was deleted."; } else { echo "Unable to delete object."; } }
include_once "login_checker.php"; // get ID of the product to be edited $product_id = isset($_GET['id']) ? $_GET['id'] : die('Missing product ID.'); // include classes include_once '../config/database.php'; include_once '../objects/product.php'; include_once '../objects/product_image.php'; include_once '../objects/product_pdf.php'; include_once "../objects/category.php"; // get database connection $database = new Database(); $db = $database->getConnection(); // initialize objects $product = new Product($db); $product_image = new ProductImage($db); $product_pdf = new ProductPdf($db); $category = new Category($db); // set page title $page_title = "Update Product"; // include page header HTML include_once "layout_head.php"; // read products button echo "<div class='right-button-margin'>"; echo "<a href='read_products.php' class='btn btn-primary pull-right'>"; echo "<span class='glyphicon glyphicon-list'></span> Read Products"; echo "</a>"; echo "</div>"; // set ID property of product to be edited $product->id = $product_id; // read the details of product to be edited $product->readOne();