redirect_head(current_url()); } //get the key, and associate it to the image record $default_image->image_wk = $database->insert_id(); //now we move the file and save $default_image->move_file(); //if the image changed, set it if ($default_image) { $new_pet->image_wk = $default_image->image_wk; } } else { $new_pet->image_wk = 0; } // insert the new pet into the database if ($new_pet->save()) { initiate_watch_list($database->insert_id(), "added"); $session->message($new_pet->name . " has been successfully added! "); $new_pet_wk = $database->insert_id(); } else { $session->message("The new pet cannot be added at this time. "); } //do the vaccinations if there are some being set if (count($_POST['vaccination']) > 0) { // add appropriate vaccinations to the pet $sql = "INSERT INTO `pet_to_vaccination` (`pet_to_vaccination_wk`, `pet_wk`, `vaccination_wk`, `create_dt`) VALUES "; $vacs = ""; foreach ($_POST["vaccination"] as $vac) { $vacs["{$vac}"] = "(NULL, '" . $new_pet_wk . "', '" . $vac . "', CURRENT_TIMESTAMP)"; } $all_vacs = implode(",", $vacs); $sql .= $all_vacs . ";";
if ($default_image) { $update_pet->image_wk = $default_image->image_wk; } } //update all form fields $update_pet->name = $_POST["name"]; $update_pet->breed_wk = $_POST["breed"]; $update_pet->color_wk = $_POST["color"]; $update_pet->status_wk = $_POST["status"]; $update_pet->age = $_POST["age"]; $update_pet->weight = $_POST["weight"]; $update_pet->create_dt = date("Y-m-d H:i:s", strtotime($_POST["create_dt"])); $update_pet->is_rescued = $_POST["rescued"]; // if the object successfully updates, go to view it if ($update_pet->save()) { initiate_watch_list($update_pet->pet_wk, "updated"); $session->message("The pet was updated successfully!"); redirect_head(ROOT_URL . "view_pet.php?pet_wk=" . $update_pet->pet_wk); } else { $session->message("The pet was not updated. " . $database->last_error); } } //header template require_once "../requires/template/header.php"; ?> <!-- form --> <section id="registration" class="container"><form class="center" role="form" action="<?php echo file_name_with_get(); ?> " enctype="multipart/form-data" method="post" ><fieldset class="registration-form">