2
votes

I have a delete button which deletes from the database. I press the delete button on my page and it will not do anything until I press it for a couple of times. Sometimes, it just deletes the value from database in one try, other times, I have to keep pressing the delete button a cuple of times for it to delete. Any way to get over this?

My view file:

//other code above

<?php $encrypted = $this->encrypt->encode($data->pid); ?>
<a href="<?php echo base_url() . "profile/delete_entry/" .  $encrypted; ?>">Delete</a>

//other code below

My controller:

$this->load->model('model_entry');

    $pid = $this->uri->segment(3);

    $result = $this->model_entry->entry_delete($pid);
    //redirect to entries index.php

My Model

public function entry_delete($pid) {

    $pid = $this->encrypt->decode($pid); //to decode

    $uid=$this->session->userdata('uid');

    $whereConditions = array('pid' => $pid, 'uid' => $uid);
    $this->db->where($whereConditions);

    $this->db->delete('dayone_entries');
}
1
Did you load the $this->load->library('encrypt'); codeigniter.com/user_guide/libraries/encryption.html I do not see it in entry_delete. Or have you auto loaded it. - Mr. ED
Hey, I have it autoloaded. - Taylor

1 Answers

1
votes

Not sure if you can place encrypted data in your URL. Codeigniter will not permit you to use a URL with special character like '='. As i know, if you do something like $encrypted = $this->encrypt->encode($data->pid); it will return a string with double '=' at the end.

Here is an explanation about encryption in CodeIgniter. Encryption string on Codeigniter