Proses edit (crud) tidak berhasil terupdate

assalamualaikum, saya masih belajar tentang php , codeigniter dan admin template, saya mendapatkan kendala ketika proses edit (crud) ketika ingin merubah datanya (update) dan click button tidak terjadi apa" dan tidak muncul kesalahannya lantas bagaimana saya mengetahui kendala tersebut saya sudah utak-atik sana sini masih blum ketemu juga kendalanya, mohon bimbingannya teman-teman sekolahkoding. ini view rolenya
<!-- Begin Page Content -->
        <div class="container-fluid">

          <!-- Page Heading -->
          <h1 class="h3 mb-4 text-light"><?= $title; ?></h1>



          <div class="row">
          	<div class="col-lg-6">
          	<?= form_error('menu', '<div class="alert alert-danger" role="alert">', '</div>'); ?>

          	<?= $this->session->flashdata('message'); ?>
          		
          	<a href="" class="btn btn-info mb-3" data-toggle="modal" data-target="#newRoleModal">Add New Role</a>

			<table class="text-light table table-hover">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col" class="text-center">Role</th>
      <th scope="col" class="text-center">Action</th>
    </tr>
  </thead>
  <tbody>
  	<?php $i = 1; ?>
  	<?php foreach ($role as $r) : ?>
    <tr>
      <th scope="row"><?= $i; ?></th>
      <td class="text-center"><?= $r['role']; ?></td>
      <td class="text-center">
		  <a href="<?= base_url('admin/roleaccess/') . $r['id']; ?>" class="badge badge-warning">access</a>
      <a href="<?= base_url(); ?>admin/edit/<?= $r['id'];?>" class="badge badge-success">edit</a>
		  <a href="<?= base_url(); ?>admin/delete/<?= $r['id'];?>" class="badge badge-danger" onclick="return confirm('Yakin?');">delete</a>

      </td>
    </tr>
    <?php $i++; ?>
	<?php endforeach; ?>
  </tbody>
</table>


          	</div>
          </div>

        </div>
        <!-- /.container-fluid -->

      </div>
      <!-- End of Main Content -->

      <!-- Modal -->

<!-- Add Modal -->
<div class="modal fade" id="newRoleModal" tabindex="-1" role="dialog" aria-labelledby="newRoleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="newRoleModalLabel">Add New Role</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">×</span>
        </button>
      </div>
      <form action="<?= base_url('admin/role'); ?>" method="post">
      <div class="modal-body">
       <div class="form-group">
    		<input type="text" class="form-control" id="role" name="role" placeholder="Role name">
  		</div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Add</button>
      </div>
      </form>
    </div>
  </div>
</div>
ini view editnya
<!-- Begin Page Content -->
        <div class="container-fluid">

          <!-- Page Heading -->
          <h1 class="h3 mb-4 text-light"><?= $title; ?></h1>
          </div>

          <div class="row pl-5">
            <div class="col-lg-6">

              <div class="card">
                <div class="card-body">
              <?= $this->session->flashdata('message'); ?>

              <form action="<?= base_url('admin/role'); ?>" method="post">
                  <input type="hidden" name="id" value="<?= $user_role['id']; ?>">
                 <div class="form-group text-gray-900">
              <label for="role">Edit Role</label>
              <input type="text" class="form-control" id="role" name="Role" value="<?= $user_role['role']; ?>">
              <?= form_error('role', ' <small class="text-danger pl-3">', '</small>'); ?>
            </div>
            <div class="form-group">
              <button type="submit" name="edit" class="btn btn-info float-right">Edit</button>
            </div>
              </form>

            </div>
          </div>
        </div>

        </div>
        <!-- /.container-fluid -->

      </div>
      <!-- End of Main Content -->
ini model role
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Role_model extends CI_Model
{

	public function DeleteRole($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('user_role');
	}

	public function GetId($id)
	{
		return $this->db->get_where('user_role', ['id' => $id])->row_array();
	}


	public function EditRole()
	{
		$data = [

			"role" => $this->input->post('role' , true)
		];

		$this->db->where('id', $this->input->post('id'));
		$this->db->update('user_role', $data);
	}




}
ini controllernya
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
		is_logged_in();
		$this->load->model('Role_model');
	}

	public function index()
	{
		$data['title'] = 'Dashboard';
		$data['title1'] = 'Overview';

		$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();

			$this->load->view('templates/header', $data);
			$this->load->view('templates/sidebar', $data);
			$this->load->view('templates/topbar', $data);
			$this->load->view('admin/index.php', $data);
			$this->load->view('templates/footer');
	}
	public function role()
	{
		$data['title'] = 'Role';
		$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();

		$data['role'] = $this->db->get('user_role')->result_array();

		$this->form_validation->set_rules('role', 'Role', 'required');

		if ($this->form_validation->run() == false) {

			$this->load->view('templates/header', $data);
			$this->load->view('templates/sidebar', $data);
			$this->load->view('templates/topbar', $data);
			$this->load->view('admin/role', $data);
			$this->load->view('templates/footer');
		} else {
			$this->db->insert('user_role', ['role' => $this->input->post('role')]);
			$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">New Role added!</div>');
			redirect('admin/role');
		} 
		
		
	}

	public function roleAccess($role_id)
	{
		$data['title'] = 'Role Access';
		$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();

		$data['role'] = $this->db->get_where('user_role', ['id' => $role_id])->row_array();

		$this->db->where('id !=', 1);
		$data['menu'] = $this->db->get('user_menu')->result_array();
		
		$this->load->view('templates/header', $data);
		$this->load->view('templates/sidebar', $data);
		$this->load->view('templates/topbar', $data);
		$this->load->view('admin/role-access', $data);
		$this->load->view('templates/footer');
	}

	public function changeAccess()
	{
		$menu_id = $this->input->post('menuId');
		$role_id = $this->input->post('roleId');

		$data = [
			'role_id' => $role_id,
			'menu_id' => $menu_id
		];

		$result = $this->db->get_where('user_access_menu', $data);

		if($result->num_rows() < 1) {
			$this->db->insert('user_access_menu', $data);
		} else {
			$this->db->delete('user_access_menu', $data);
		}

		$this->session->set_flashdata('message', '<div class="alert-success" role="alert">Access Changed!</div>');
	}


	public function delete($id) 
	{
		$this->Role_model->DeleteRole($id);
		$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Role Deleted!</div>');
		redirect('admin/role');
	}

	public function edit($id)
	{
		$data['title'] = 'Role';
		$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
		$data['user_role'] = $this->Role_model->GetId($id);

		$this->form_validation->set_rules('role', 'Role', 'required');

		if ($this->form_validation->run() == false) {

			$this->load->view('templates/header', $data);
			$this->load->view('templates/sidebar', $data);
			$this->load->view('templates/topbar', $data);
			$this->load->view('admin/edit', $data);
			$this->load->view('templates/footer');
		} else {
			$this->Role_model->EditRole();
			$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Role Edited!</div>');
			redirect('admin/role');
		} 
		
		
	}
}
avatar DwiGigih

Ditanyakan oleh @DwiGigih

3 Kontribusi 0 Poin

Login untuk menanggapi


Jawaban

Coba cek baris ini di bagian view
<form action="<?= base_url('admin/role'); ?>" method="post">
Bukankah seharusnya seperti ini?
<form action="<?= base_url('admin/edit'); ?>" method="post">
Semoga membantu
avatar Ahmad554

Dijawab oleh @Ahmad554

52 Kontribusi 19 Poin

  • hasilnya jadi seperti ini gan https://imgur.com/FPEVddE - @DwiGigih
  • Itu argumennya kosong, dia bingung mau edit data yg mana. Coba cek url nya saat cursor di arahkan ke tombol edit. Apakah ada id nya? - @Ahmad554
  • sebelum saya pencet tombol button edit idnya muncul tapi setelah diclick muncul eror seperti gambar di atas - @DwiGigih

Login untuk menanggapi


Login untuk gabung berdiskusi