<meta charset="utf-8" /> <link rel="stylesheet" href="styles.css" /> <title>Potion Shop Inventory</title> </head> <body> <h1>Potion Shop Inventory</h1> <?php # Check for success message trigger and display accordingly if (isset($_GET["success"])) { switch ($_GET["success"]) { case "add": echo "<p class='success-add'>Potion added successfully.</p>"; break; case "delete": echo "<p class='success-delete'>Potion removed successfully.</p>"; break; case "edit": echo "<p class='success-edit'>Potion updated successfully.</p>"; break; } } $myShop = new PotionShop(); # Instantiate an Object using our PotionShop Class $myShop->displayPotions(); # Call the displayPotions method through the new Object ?> </body> </html>
<?php require_once 'class.PotionShop.php'; $myShop = new PotionShop(); $error = 0; # Setup page information and execute code based on which button was pressed switch ($_POST["btn_action"]) { case "Add Potion": $btn_value = "Add Potion"; $action = "add"; break; case "Delete Potion": if (!$_POST["potion_id"]) { header("location: index.php"); exit; } $myShop->removePotion($_POST["potion_id"]); break; case "Edit Potion": if (!$_POST["potion_id"]) { header("location: index.php"); exit; } $btn_value = "Edit Potion"; $action = "edit"; $edit_potion = $myShop->singlePotion($_POST["potion_id"]); foreach ($edit_potion as $key => $value) { ${$key} = $value; } break; default: