$date_established = $firstDate . '-' . $secondDate . '-' . $thirdDate; } catch (Exception $e) { $errors['date_established'] = $e->getMessage(); } try { $area_in_acres = Input::get_number('area_in_acres'); } catch (Exception $e) { $errors['area_in_acres'] = $e->getMessage(); } try { $park_img = Input::get_string('park_img'); } catch (Exception $e) { $errors['park_img'] = $e->getMessage(); } try { $describtion = Input::get_string('describtion'); } catch (Exception $e) { $errors['describtion'] = $e->getMessage(); } var_dump($errors); $stmt = $dbc->prepare('INSERT INTO national_parks(name,location,date_established,area_in_acres,park_img,describtion) VALUES (:name,:location,:date_established,:area_in_acres,:park_img,:describtion)'); if (empty($errors)) { $stmt->bindValue(':name', $name, PDO::PARAM_STR); $stmt->bindValue(':location', $location, PDO::PARAM_STR); $stmt->bindValue(':date_established', $date_established, PDO::PARAM_STR); $stmt->bindValue(':area_in_acres', $area_in_acres, PDO::PARAM_INT); $stmt->bindValue(':park_img', $park_img, PDO::PARAM_STR); $stmt->bindValue(':describtion', $describtion, PDO::PARAM_STR); $stmt->execute(); }
/** * Binds input to model fields. * * @param Input $input Input to fetch values from (Input::Get() or Input::Post()) * @param array $allowed Map of form fields to field names, required. */ function bind_input($input, $allowed) { foreach ($allowed as $form_name => $name) { if ($input->exists($form_name) && $this->fields[$name] != null) { switch ($this->fields[$name]->type) { case Field::NUMBER: $this->__set($name, $input->get_num($form_name)); break; case Field::TIMESTAMP: $this->__set($name, $input->get_date($form_name)); break; case Field::BOOLEAN: $this->__set($name, $input->get_boolean($form_name)); break; case Field::MULTI: $this->__set($name, $input->get_array($form_name)); break; case Field::OBJECT: break; default: $this->__set($name, $input->get_string($form_name)); break; } } } }