crud不受影响

nbnkbykc  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(372)

我一直在努力制造一些积垢我什么都没弄错。但当我更新数据时,数据库和我的代码没有受到任何影响
表:歌曲栏:id\歌曲、id\专辑、歌曲、作者、 composer
我的型号代码如下:

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');
     }

看到我没有错,但当我编辑并试图更新一些数据,它不受影响。

kzmpq1sx

kzmpq1sx1#

希望这能帮助您:
你使你残疾了 id_song 输入您的 form 把它拿走 disabled 它的属性
因为这个你无法得到 id_song 在您的 update_song 方法,而不是进入你的 where 条款so id_song 输入应如下所示:

<div class="form-group">
    <label for="userName">id_songs </label>
    <input type="text" 
           name="id_song" 
           value="<?php echo $data->id_song; ?>" 
           class="form-control"  id="userName">
 </div>

或者如果你不想这样表现的话就把它藏起来:

<input type="hidden" 
           name="id_song" 
           parsley-trigger="change" required
           value="<?php echo $data->id_song; ?>" 
           class="form-control"  id="userName">

相关问题