$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; $productPdf->upload(); echo "<div class=\"alert alert-success alert-dismissable\">"; echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>"; echo "Product was created."; echo "</div>"; } else { echo "<div class=\"alert alert-danger alert-dismissable\">"; echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>"; echo "Unable to create product."; echo "</div>"; } } ?>
$product->id = $product_id; // read the details of product to be edited $product->readOne(); // if the form was submitted if ($_POST) { // 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']; // update the product if ($product->update()) { // save the images $product_image->product_id = $product_id; $product_image->upload(); // save the pdf files $product_pdf->product_id = $product_id; $product_pdf->upload(); echo "<div class=\"alert alert-success alert-dismissable\">"; echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>"; echo "Product was updated."; echo "</div>"; } else { echo "<div class=\"alert alert-danger alert-dismissable\">"; echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>"; echo "Unable to update product."; echo "</div>"; } } ?>