0

I'm trying to delete data from my database

Here's my code:

VIEW

<table border="1" class="table">
    <tr>
        <th>No</th>
        <th>Nama Depan</th>
        <th>Nama Belakang</th>
        <th>TTL</th>
        <th>Email</th>
        <th>Keterangan</th>
    </tr>
    <?php 
    $i = 0;
    foreach ($dataMember as $result) { ?>
    <tr>
        <td><?php echo ($i+1); ?></td>
        <td><?php echo $result['namaDepan'];?></td>
        <td><?php echo $result['namaBelakang']; ?></td>
        <td><?php echo $result['TTL']; ?></td>
        <td><?php echo $result['email']; ?></td>
        <td>
        <a href="<?php echo base_url() . "BelajarBerhadiah/hapusMember/" . $result->email; ?>"><button>Delete</button></a>  
        </td>
        
    </tr>
    <?php $i++; } ?> 
</table>

MODEL

public function Hapusdata($id){
    $this->db->where('email', $id);
    $this->db->delete('daftar');
}

Controller

public function hapusMember()
    {           
        $this->load->model('Member'); 
        $this->load->helper('url');
        $id = $this->uri->segment(3);
        $this->Member->Hapusdata($id);
        redirect (site_url('Belajarberhadiah/halaman_admin'));
    }

and the problem is i get

Severity: Notice

Message: Trying to get property of non-object

Filename: views/halaman_dMember.php

Line Number: 105

What should i do?

Community
  • 1
  • 1
  • 1
    FYI: Your code has a significant security vulnerability if it can work this way. This would mean your code has a delete link that can be activated via a HTTP GET request: [this means web trawlers can activate it and delete your stuff](http://stackoverflow.com/q/786070/254830), or I can send you an email with `` in it. (If your email client tries to retrieve that image, it activates that link and deletes that user.) Your modification actions should always rely on POST and other non-GET HTTP request types. – doppelgreener Dec 05 '16 at 12:25
  • thank you sir for that information.... i really know nothing about that stuff,, i just try suggestion from my friend... the real thing is i just want to delete user from my database use CI, im so new in this CI thing so i search from any source but i cant found any answer :( @doppelgreener – Ricky Guinta Dec 05 '16 at 12:35
  • Since you're getting into web development, you'd better learn about HTTP requests - they're pretty important! [Here's a tutorial that seems to cover the HTTP protocol decently.](https://code.tutsplus.com/tutorials/http-the-protocol-every-web-developer-must-know-part-1--net-31177) – doppelgreener Dec 05 '16 at 12:37
  • Thanks yous sirr its really helpful for me i will learn that @doppelgreener – Ricky Guinta Dec 05 '16 at 12:39
  • You need to provide the code for the controller which loads your view. The code you provided for controller is the code works when the link in view has been clicked. – kishor10d Dec 05 '16 at 18:02
  • ohhh i see ^^ i try it and its work,, i didnt see that btw thanks @kishor10d – Ricky Guinta Dec 05 '16 at 18:58
  • deleting with email is not good practice – Jagdish Chaudhary Jan 18 '19 at 10:56

1 Answers1

1

Please write href for delete tag as below:

<a href ="<?php echo site_url('BelajarBerhadiah/hapusMember/1');?>">delete</a>

Also be sure that the column[email] you have used for where condition in controller is the correct one. Because column name is "email" in where condition and you are passing an integer value.

Krish Munot
  • 1,093
  • 2
  • 18
  • 29
Hina
  • 11
  • 2