Add product"; if (isset($_POST["addSubmit"])) { // Code to check that all collums have values if ((!empty($_POST["nameame"])) && (!empty($_POST["description"])) && (!empty($_POST["price"])) && (!empty($_POST["cost_price"])) && (!empty($_POST["stock"])) && (!empty($_POST["link"])) && (!empty($_POST["ean"]))) { //Code to add/insert new data into the table $query = "INSERT INTO tbl_products (name, description, price, cost_price, stock, ean, link) " . "VALUES ('" . $_POST["name"] . "', '" . $_POST["description"] . "', " . "'" . $_POST["price"] . "', '" . $_POST["cost_price"] . "', " . $_POST["stock"] . ", '" . $_POST["ean"] . "','" . $_POST["link"] . "');"; $result = mysqli_query($connection, $query); //Code to check if the insert query was successful or not if ($result == false) { echo "

Adding product " . $_POST["name"] . " failed.

"; } else { echo "

The product \"" . $_POST["name"] . "\" has been added to the product " . "catalogue. The product details are:" . "

"; } //Code to display error if user has not added all of the information } else { echo "

Please fill in all of the add form

"; } } ?>
Update product"; if (isset($_POST["updateSubmit"])) { if ((!empty($_POST["name"])) && (!empty($_POST["description"])) && (!empty($_POST["price"])) && (!empty($_POST["cost_price"])) && (!empty($_POST["stock"])) && (!empty($_POST["link"])) && (!empty($_POST["ean"]))) { $query = "UPDATE products " . "SET name = '" . $_POST["name"] . "', " . "description = '" . $_POST["description"] . "', " . "price = '" . $_POST["price"] . "', " . "cost_price = '" . $_POST["cost_price"] . "', " . "stock = " . $_POST["stock"] . ", " . "ean = '" . $_POST["ean"] . "', " . "link = '" . $_POST["link"] . "' " . "WHERE id=" . $_GET['id'] . ";"; $result = mysqli_query($connection, $query); if ($result == false) { echo "

Updating product " . $_POST["name"] . " failed.

"; } else{ echo "

The product \"" . $_POST["name"] . "\" has been updated in the " . "product catalogue. The new product details are:" . "

"; } } else { echo "

Please fill in all of the data requested in the form.

"; } } $query = "SELECT * FROM tbl_products WHERE id=" . $_GET["id"] . ";"; $result = mysqli_query($connection, $query); if ($result == false) { echo "

Failed to find product details.

"; } else { $productDetails = mysqli_fetch_array($result, MYSQLI_ASSOC); if (empty($productDetails)) { echo "

No product details were found.

"; } } ?>
" method="post">
">
">
">
">
">
Getting product details failed.

"; } else { $productDetails = mysqli_fetch_array($result, MYSQLI_ASSOC); if (empty($productDetails)) { echo "

The ID that you entered has not found anything, please try again.

"; } else { $query = "DELETE FROM tbl_products WHERE id=" . $_GET["id"] . ";"; $result = mysqli_query($connection, $query); if ($result == false) { echo "

The product with id of " . $_GET["id"] . " (" . $productDetails["name"] . ") has not been deleted.

"; } else { echo "

The product with id of " . $_GET["id"] . " (" . $productDetails["name"] . ") has been deleted.

"; } } } } ?>

Products in stock