1

This is my controller function:

function delete_article($title){

    if ($this->session->userdata('User') && $this->session->userdata('User') == '[email protected]') {

        $this->load->model('Article', 'Article', TRUE);
        $this->Article->delete_article_db($title);

        redirect('admin/user_article');
    } else {
        redirect('');
    }
}

And this is my model function for deleting the database record:

 function delete_article_db($title) {
    $this->db->where('Title', $title);
    $this->db->delete('article');
}

When I run this code, nothing gets deleted. However, the code does not fire any errors or warnings.

This is my MySQL table structure:

CREATE TABLE IF NOT EXISTS `article` (
   `Name` text NOT NULL,
   `Email` text NOT NULL,
   `Phone` text NOT NULL,
   `Address` text NOT NULL,
   `Literature` text NOT NULL,
   `Title` text NOT NULL,
   `Submission_Name` text NOT NULL,
   `Additional_Name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6
  • 3
    Check CodeIgnitor logs? Commented Nov 26, 2013 at 17:52
  • did you check that there's an article with this title? Did you check server logs? Commented Nov 26, 2013 at 17:52
  • Does it work with $this->db->delete('article', array('Title' => $title)); ? Commented Nov 26, 2013 at 17:53
  • Database class is preloaded? Commented Nov 26, 2013 at 17:55
  • @André Sir not working with your solution.. :( Commented Nov 26, 2013 at 17:59

1 Answer 1

3

A bit of a wild guess, but looking at your controller method, and the variable names, I'm assuming you're passing the title via url, something like

http://example.com/admin/delete/Title to be deleted

Which leads me to think your query is not working because of encoding of the spaces in the url (or other characters) which won't match the not encoded spaces in your db.

Try with:

function delete_article_db($title) {
    $this->db->where('Title', rawurldecode($title) );
    $this->db->delete('article');
}
Sign up to request clarification or add additional context in comments.

2 Comments

PERFECT WORKS.. FOR ME NOW.. THANK YOU VERY MUCH SIR.. I AM SOLVING THIS FROM LAST 2 HOURS THANK YOU AGAIN SIR.. :)
Glad it worked! :) As an advice: always var_dump() a variable when you're not sure about its content (like in where clause)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.