Есть View:
<form method="POST" action="/main/addFilm">
<div class="form-group mt-4">
<label for="exampleFormControlInput1">Movie title</label>
<input name="title" type="text" class="form-control" id="exampleFormControlInput1" placeholder="" >
</div>
<div class="form-group">
<label for="inputDate">Year</label>
<input name="release" type="text" class="form-control" >
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Format</label>
<select name="format" class="form-control" id="exampleFormControlSelect1" >
<option>VHS</option>
<option>DVD</option>
<option>Blue-Ray</option>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Actors</label>
<textarea name="actors" class="form-control" id="exampleFormControlTextarea1" rows="3" ></textarea>
</div>
<button type="submit" class="btn btn-primary mb-3">Add</button>
</form>
Потом контроллер:
/**
*
*/
public function addFilmAction()
{
$data = $this->model->addFilms();
$this->view->generate('add_film_view.php', $data);
}
И модель:
public function addFilms()
{
$title = (isset($_POST['title']) && (!empty($_POST['title'])) ? $_POST['title'] : false );
$release = (isset($_POST['release']) && (!empty($_POST['release'])) ? $_POST['release'] : false );
$format = (isset($_POST['format']) && (!empty($_POST['format'])) ? $_POST['format'] : false );
$actors = (isset($_POST['actors']) && (!empty($_POST['actors'])) ? $_POST['actors'] : false );
if ($this->connect()) {
$sql = "INSERT INTO films (title, release, format, actors)
VALUES ( :title, :release, :format, :actors)";
$stmt = $this->connect()->prepare($sql);
$stmt->bindParam(':title', $title, PDO::PARAM_STR);
$stmt->bindParam(':release', $release, PDO::PARAM_STR);
$stmt->bindParam(':format', $format, PDO::PARAM_STR);
$stmt->bindParam(':actors', $actors, PDO::PARAM_STR);
$stmt->execute();
}
}
Может что то упустил, оно работала, потом перестало, стоит автозагрузка классов