我一直在努力做一些 CRUD 我没有错。但是当我更新数据时,我在数据库中没有受到任何影响,这里是我的代码
表:歌曲 列: id_song、id_album、歌曲、作者、作曲家
我的模型代码如下:
function Tampil_song_admin(){
return $this->db->get('songs');
}
function Input_song($data,$table){
$this->db->insert($table,$data);
}
function edit_song($where,$table){
return $this->db->get_where($table,$where);
}
function update_song($where,$data,$table){
$this->db->where($where);
$this->db->update($table,$data);
}
function delete_song($where,$table){
$this->db->where($where);
$this->db->delete($table);
}
看法:
<?php foreach($songs as $data){ ?>
<form action="<?php echo base_url('/index.php/Admin_song/update_song'); ?>" method="post">
<h4 class="header-title m-t-0 m-b-30"></h4>
<div class="form-group">
<label for="userName">id_songs </label>
<input type="text" name="id_song" parsley-trigger="change" required
value="<?php echo $data->id_song; ?>"
class="form-control" disabled="" id="userName">
</div>
<div class="form-group">
<label for="userName">id_album</label>
<input type="text" name="id_album" parsley-trigger="change" required
value="<?php echo $data->id_album; ?>" class="form-control" id="userName">
</div>
<div class="form-group">
<label for="userName">Songs</label>
<input type="text" name="song" parsley-trigger="change" required
value="<?php echo $data->song; ?>" class="form-control" id="userName">
</div>
<div class="form-group">
<label for="userName">Author</label>
<input type="text" name="author" parsley-trigger="change" required
value="<?php echo $data->author; ?>" class="form-control" id="userName">
</div>
<div class="form-group">
<label for="userName">Composer</label>
<input type="text" name="composer" parsley-trigger="change" required
value="<?php echo $data->composer; ?>" class="form-control" id="userName">
</div>
<button type="submit" class="btn btn-success waves-effect w-md waves-light m-b-5">Update</button>
<button type="button" class="btn btn-danger waves-effect w-md waves-light m-b-5">Reset</button>
</form>
<?php } ?>
这是针对控制器的:
function index(){
$data['songs'] = $this->m_admin_data->Tampil_song_admin()->result();
$this->load->view('admin/v_admin_song',$data);
}
//Tambah Data
function add_song(){
$this->load->view('admin/v_admin_song_add');
}
function proses_tambah(){
$id_album = $this->input->post('id_album');
$song = $this->input->post('song');
$author = $this->input->post('author');
$composer = $this->input->post('composer');
$data = array(
'id_album' => $id_album,
'song' => $song,
'author' => $author,
'composer' => $composer
);
$this->m_admin_data->Input_song($data,'songs');
redirect('Admin_song/index');
}
//Update/Edit Data
function edit_song($id){
$where = array('id_song' => $id);
$data['songs'] = $this->m_admin_data->edit_song($where,'songs')->result();
$this->load->view('admin/v_admin_song_edit',$data);
}
function update_song(){
$id = $this->input->post('id_song');
$id_album = $this->input->post('id_album');
$song = $this->input->post('song');
$author = $this->input->post('author');
$composer = $this->input->post('composer');
$data = array(
'id_album' => $id_album,
'song' => $song,
'author' => $author,
'composer' => $composer
);
$where = array(
'id_song' => $id
);
$this->m_admin_data->update_song($where,$data,'songs');
redirect('Admin_song/index');
}
//Hapus Data
function delete_song($id){
$where = array('id_song' => $id);
$this->m_admin_data->delete_song($where,'songs');
redirect('Admin_song/index');
}
看到我没有错,但是当我编辑并尝试更新一些数据时,它不受影响。