public function add() { $products = new products(); if ($_POST) { if ($products->addProduct($_POST['name'], $_POST['amount'], $_POST['value'], $_POST['id'])) { $this->success = true; $this->msg = "Produto cadastrado com sucesso!"; } else { $this->success = false; $this->msg = "Erro ao efetuar o cadastro, por favor, tente novamente."; } } $lastID = $products->getLastProductID() + 1; $success = $this->success; $msg = $this->msg; require_once 'view/product_add_view.php'; }
function addProduct() { include_once "products.php"; $product = new products(); $fname = $_REQUEST['fname']; $fcateg = $_REQUEST['fcateg']; $fprice = $_REQUEST['fprice']; $pic = $_REQUEST['pic']; if (!$product->addProduct($fname, $fcateg, $fprice, $pic)) { echo '{"result":0,"message":"Could not add the product"}'; return; } echo '{"result":1,"message":"Succesfully added product"}'; }