Welcome Guest, Not a member yet? Register   Sign In
no database action
#1

[eluser]GamingFusion[/eluser]
I have a file that is supposed to delete a show from the database.

so i pass through to the function showDelete the thrid segemnt of the uri. but it doesnt do it all it does is pull up a blank page. i checked to make sure that the function is being called and it is.

heres my code

database model
Code:
function deleteShow()
    {        
        $query = $this->db->delete('shows', array('id' => segement(3)));
        
        if ($query) {
            return $data['deleted'] = TRUE;
        }else{
            return $data['deleted'] = FALSE;
        }
    }

controller
Code:
function showDelete()
    {
        //Set Data
        $data['title'] = 'Theater 311 | Remove Show';
        $data['heading'] = 'Remove Show';
        
        //Delete Show
        $this->database->deleteShow();
        
        //Load View
        $this->load->view('deleteShow', $data);
    }

and finally the view file
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;?php
    if ($deleted = TRUE) {
        echo '<h1>Success!</h1>
        <h3>The Show has Been removed</h3>';
    }else{
        echo '<h1>Failure!</h1>
        <h3>The Show was not removed</h3>';
    }
?&gt;
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]pistolPete[/eluser]
If you get a blank page, you should enable error_reporting in index.php and see if you get any errors:
Code:
error_reporting(E_ALL);

Do you have a function called segement()?

I'd rather use this code:
controller:
Code:
function showDelete($id = FALSE)
{
        //Set Data
        $data['title'] = 'Theater 311 | Remove Show';
        $data['heading'] = 'Remove Show';
        
        //Delete Show
        $data['deleted']  = $this->database->deleteShow($id);
        
        //Load View
        $this->load->view('deleteShow', $data);
}

model:
Code:
function deleteShow($id = FALSE)
{        
        if($id === FALSE)
        {
                return FALSE;
        }
        $query = $this->db->delete('shows', array('id' =>$id));
        return $query;
}
#3

[eluser]GamingFusion[/eluser]
SOLVED

my problem was that i was using was using

Code:
segment(3)

instead of

Code:
$this->uri->segment(3)
#4

[eluser]Aken[/eluser]
Glad you solved your problem. However I agree with pistolPete, you should pass the URL segment as a parameter in the model function. It will make the function more versatile, in case you want to use it elsewhere when the URL segment isn't available, but the ID is.




Theme © iAndrew 2016 - Forum software by © MyBB