Форма не заполняется данными. как исправить?
1
Написал вроде всё как надо, чтобы можно было редактировать фильмы, но форма не хочет заполняться данными из бд. В чём проблема?
$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['movies/rating'] = 'movies/rating';
$route['movies/(:any)'] = 'movies/view/$1';
$route['movies/type/films'] = 'movies/type/films/$1';
$route['movies/type/serials'] = 'movies/type/serials/$1';
$route['news'] = 'news';
$route['news/create'] = 'news/create';
$route['news/createpost'] = 'news/createpost';
$route['news/createfilms'] = 'news/createfilms';
$route['news/edit'] = 'news/edit';
$route['news/editpost'] = 'news/editpost';
$route['news/editfilms'] = 'news/editfilms';
$route['news/delete'] = 'news/delete';
$route['news/post'] = 'news/deletepost';
$route['news/files'] = 'news/files';
$route['news/(:any)'] = 'news/view/$1';
$route['search'] = 'search';
public function editfilms($slug = NULL) {
if (!$this->dx_auth->is_admin()) {
//show_404();
$this->load->helper('url_helper');
redirect("/", "location");
}
$this->data['title'] = "Редактировать фильм";
$this->data['movie_item'] = $this->news_model->getFilms($slug);
$this->data['name_movie'] = $this->data['movie_item']['name'];
$this->data['description_movie'] = $this->data['movie_item']['description'];
$this->data['slug_movie'] = $this->data['movie_item']['slug'];
$this->data['slug_movie'] = $this->data['movie_item']['year'];
$this->data['slug_movie'] = $this->data['movie_item']['rating'];
$this->data['slug_movie'] = $this->data['movie_item']['poster'];
$this->data['slug_movie'] = $this->data['movie_item']['add_date'];
$this->data['slug_movie'] = $this->data['movie_item']['producer'];
if ($this->input->post('slug') && $this->input->post('name') && $this->input->post('year') && $this->input->post('descriptions') && $this->input->post('rating') && $this->input->post('add_date') && $this->input->post('poster') && $this->input->post('producer')) {
$slug = $this->input->post('slug');
$name = $this->input->post('name');
$descriptions = $this->input->post('descriptions');
$year = $this->input->post('year');
$rating = $this->input->post('rating');
$poster = $this->input->post('poster');
$add_date = $this->input->post('add_date');
$producer = $this->input->post('producer');
if ($this->news_model->updateFilms($slug, $name, $descriptions, $year, $rating, $poster, $add_date, $producer)) {
echo "Фильм успешно отредактирован";
}
}
$this->load->view('templates/header', $this->data);
$this->load->view('news/editfilms', $this->data);
$this->load->view('templates/footer');
}
public function getFilms($slug = FALSE) { // выводит данные из бд
if($slug === FALSE){
$query = $this->db->get('movie');
return $query->result_array();
}
$query = $this->db->get_where('movie', array('slug' => $slug));
return $query->row_array();
}
public function updateFilms($slug, $name, $descriptions, $year, $rating, $poster, $add_date, $producer) {
$data = array(
'name' => $name,
'slug' => $slug,
'descriptions' => $descriptions,
'year' => $year,
'rating' => $rating,
'poster' => $poster,
'add_date' => $add_date,
'producer' => $producer
);
return $this->db->update('movie', $data, array('slug' => $slug));
}
//форма редактирования фильмов
<form action="/news/editfilms/" method="post">
<input class="form-control input-lg" type="input" name="slug" placeholder="slug"></br>
<input class="form-control input-lg" type="input" name="name" placeholder="фильм"></br>
<input class="form-control input-lg" type="input" name="year" placeholder="year"></br>
<input class="form-control input-lg" type="input" name="rating" placeholder="rating"></br>
<input class="form-control input-lg" type="input" name="poster" placeholder="poster"></br>
<input class="form-control input-lg" type="input" name="add_date" placeholder="add_date"></br>
<input class="form-control input-lg" type="input" name="producer" placeholder="producer"></br>
<textarea name="descriptions" placeholder="Описание фильма/сериала"></textarea></br>
<input class="btn btn-default" type="submit" name="submit" value="редактировать фильм">
</form>
1 ответов
1
Если речь идет о форме редактировании фильма, то у вас не хватает в формах value, типа такого:
<input class="form-control input-lg" type="input" name="slug" value="<?php echo $slug_movies; ?>" placeholder="slug"><br>
<input class="form-control input-lg" type="input" name="name" value="<?php echo $name_movies; ?>" placeholder="название фильма"><br>
<textarea class="form-control input-lg" name="descriptions" placeholder="описание"><?php echo $descriptions_movies; ?></textarea><br>
<input class="form-control input-lg" type="input" name="year" value="<?php echo $year_movies; ?>" placeholder="год"><br>
<input class="form-control input-lg" type="input" name="rating" value="<?php echo $rating_movies; ?>" placeholder="рейтинг"><br>
<input class="form-control input-lg" type="input" name="poster" value="<?php echo $poster_movies; ?>" placeholder="ссылка на постер"><br>
<input class="form-control input-lg" type="input" name="player_code" value="<?php echo $player_code_movies; ?>" placeholder="ссылка на плеер"><br>
<input class="form-control input-lg" type="input" name="director" value="<?php echo $director_movies; ?>" placeholder="режиссер"><br>
<input class="form-control input-lg" type="input" name="add_date" value="<?php echo $add_date_movies; ?>" placeholder="дата добавления"><br>
<input class="form-control input-lg" type="input" name="category_id" value="<?php echo $category_id_movies; ?>" placeholder="категория (1=фильм; 2=сериал)"><br>
<input type="submit" class="btn btn-success" name="submit" value="Редактировать фильм/сериал">