public function post() { $car = new CarModel($_POST['guid']); $car->setMake($_POST['make']); $car->setModel($_POST['model']); $car->setYear($_POST['year']); $car->setImage($_POST['image']); // Save picture of the car if picture submitted if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { // Replace the existing image with a new image of a car if (isset($_POST['image']) && !empty($_POST['image'])) { parent::deleteFile($_POST['image']); } parent::saveFile(); $path = 'uploads/' . $_FILES['file']['name']; $car->setImage($path); $car->save(); } else { if (isset($_POST['delete'])) { // Delete the car and its image $car->delete(); parent::deleteFile($_POST['image']); } else { $car->save(); } } if (headers_sent()) { die('Redirect failed. Please go back to home page'); } else { exit(header('Location: index.php')); } }
public static function post() { $make = $_POST['make']; $model = $_POST['model']; $year = $_POST['year']; $car = new CarModel(); $car->setMake($make); $car->setModel($model); $car->setYear($year); $car->save(); Paragraph::newParagraph('Congratulations! You\'ve successfully added a new car!'); echo Link::newLink('<< Back', 'index.php', '_self'); }
public function __construct($post_array = '') { isset($_POST['guid']) ? $car = new CarModel($_POST['guid']) : ($car = new CarModel()); $car->setMake($_POST['make']); $car->setModel($_POST['model']); $car->setYear($_POST['year']); isset($_POST['delete']) ? $car->delete() : $car->save(); if (headers_sent()) { die('Redirect failed. Please go back to home page'); } else { exit(header('Location: ./index.php')); } }
public function post() { $car = new CarModel(); $car->setMake($_POST['make']); $car->setModel($_POST['model']); $car->setYear($_POST['year']); // Save picture of the car if picture submitted if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { $src = parent::saveFile(); $path = 'uploads/' . $_FILES['file']['name']; $car->setImage($path); $car->save(); } else { $car->save(); } // Redirect if (headers_sent()) { die('Redirect failed. Please go back to home page'); } else { exit(header('Location: index.php')); } }