Welcome Guest, Not a member yet? Register   Sign In
Help required with update and insert
#11

[eluser]the_unforgiven[/eluser]
When i clcik the edit link to go to the following url: http://localhost/ci/admin/update/69

it grabs the id and does eaxtly what it's suppose to but when navigating to the above a blank white screen appears nothing else
#12

[eluser]the_unforgiven[/eluser]
I've edited the form to incorporte what you said but still blank screen Sad

Code:
echo form_open('admin/update/'.$id); ?>
<table name="editform" cellpadding="1">
    <tr>
        <td class="table_title">Page Title:</td>
        <td>&lt;input type="text" name="name" title="name" value="&lt;?php echo set_value('name', $name); ?&gt;" /&gt;&lt;/td>
    </tr>
    <tr>
        <td class="table_title">Description:</td>
        <td>&lt;textarea name="description" title="description"  cols="50" rows="8"&gt;&lt;?php echo set_value('description', $description); ?&gt;&lt;/textarea&gt;&lt;/td>
    </tr>
    <tr>
        <td class="table_title">Keywords:</td>
        <td>&lt;input type="text" name="keywords" title="keywords"  value="&lt;?php echo set_value('keywords', $keywords); ?&gt;" /&gt;&lt;/td>
        <td><small>max 5 keywords seperated by a comma ,</small></td>
    </tr>
    <tr>
        <td class="table_title">Content:</td>
        <td>&lt;textarea name="content" title="Content" cols="50" rows="8"&gt;&lt;?php echo set_value('content', $content); ?&gt;&lt;/textarea&gt;&lt;/td>
        <td><small>max 2000 characters</small></td>
    </tr>

    <tr>
        <td class="table_title"></td>
        <td>&lt;input type="hidden" name="lang_id" value="1" /&gt;&lt;/td>
        <td>&lt;input type="hidden" name="id" value="&lt;?php echo set_value('id', $id); ?&gt;" /&gt;&lt;/td>
        <td>&lt;input type="hidden" name="form" value="edit" /&gt;&lt;/td>
    </tr>
    <tr>
        <td class="table_title"></td>
        <td>&lt;input type="submit" name="submit" value="Save" /&gt;&lt;/td>
    </tr>
    <tr>
        <td class="table_title"></td>
        <td><a href="admin/pages" title="Back">Back</a></td>
    </tr>
</table>
&lt;?php
echo form_close();
#13

[eluser]the_unforgiven[/eluser]
Also i understand the code wasn't meant for me to work “out of the box” but it made sense and by re-using that code will make me understand more than sat here thinking how do you do .... ..... etc
#14

[eluser]LuckyFella73[/eluser]
Quote:When i clcik the edit link to go to the following url: http://localhost/ci/admin/update/69
it grabs the id and does eaxtly what it’s suppose to but when navigating to the above a blank white screen appears nothing else

Don't you get the prefilled form at all or do you get a blank page after submitting?

btw.: if you have this in your controller when calling your model:
Code:
if ( $query === FALSE) // .....
You have to return 'true' or 'false' depending if the query worked.
Otherwise your code allways 'thinks' it's 'false'.

Code:
//Update page model
function update_page($data)
{
    //$id = $this->input->get('id');
    $this->db->where('id', $this->input->post('id'));

    if ( $this->db->update('ci_pages', $data) )
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
#15

[eluser]the_unforgiven[/eluser]
I just get a blank screen when the link is clicked doesn't even show the edit form
#16

[eluser]the_unforgiven[/eluser]
Just going through the code now i think something is missing like a ; or something for it to be a blank screen once the link is clicked otherwise if it was anything else it show an error or even so they form had been populated, right??
#17

[eluser]the_unforgiven[/eluser]
I'm guessing this IF statement has something to do with it cos when i changed it something completely random it throws back an error

Code:
if (isset($_POST['form']) AND $_POST['form'] == 'edit')
#18

[eluser]LuckyFella73[/eluser]
I have this line in a running project and it works so I assume
that can't be the error.

Maybe the error is somewhere else in your controller? Could you
post the whole controller code?
#19

[eluser]the_unforgiven[/eluser]
Yes sure here it is:
Code:
&lt;?php
class Admin extends CI_Controller {
    
    
    function index()
    {    
        // Load Libary & Helper Files
        $this->load->database('ci');
        $this->load->library(array('encrypt', 'form_validation', 'pagination', 'session'));
        $this->load->helper(array('form', 'url'));
        $this->load->view('admin/dashboard');
        $id = $this->session->userdata('session_id');
    }
    
    
    
    
    // Success for edited page
    function pagesuccess() {
        $data['title'] = 'Page Updated';
        $this->load->view('admin/pagesuccess', $data);            
    
    }
    // Pages Function
    function pages() {

        $data = array();
        
        if($query = $this->page_model->getAllPages())
        {
            $data['pages'] = $query;
            $data['title'] = 'Page Management';
        }
        
        $this->load->view('admin/pages', $data);

    }
    //Update Function
    function update() {
            $this->load->helper('form');
            $this->load->library('form_validation');
            
            if (!empty($_POST['form']) AND $_POST['form'] == 'edit')
            {
                # Form was send:
                $this->id = $this->input->post('id');

                $this->load->helper('form');
                $this->load->library('form_validation');

                # Rules:
                $this->form_validation->set_rules('name', 'Page Title', 'trim|required|min_length[2]|max_length[120]|xss_clean');
                $this->form_validation->set_rules('description', 'Description', 'trim|required|min_length[3]|max_length[160]|xss_clean');
                $this->form_validation->set_rules('keywords', 'Keywords', 'trim|required|min_length[3]|max_length[160]|xss_clean');
                $this->form_validation->set_rules('content', 'Content', 'trim|required|min_length[3]|max_length[2000]|xss_clean');



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

                    $data['id'] = $this->input->post('id');
                    $data['name'] = $this->input->post('name');
                    $data['description'] = $this->input->post('description');
                    $data['keywords'] = $this->input->post('keywords');
                    $data['content'] = $this->input->post('content');
                    $data['status'] = $this->input->post('status');

                    $this->load->view('admin/editpage', $data);
                }
                else
                {                
                    $data = array(
                        'name' => $this->input->post('name'),
                        'description' => $this->input->post('description'),
                        'keywords' => $this->input->post('keywords'),
                        'content' => $this->input->post('content'),
                        'status' => $this->input->post('status')                

                    );

                    $query = $this->page_model->update_page($data, $this->id);

                    if ( $query === FALSE)
                    {
                        $data['msg'] .= 'failed'; // echo in view file
                    }
                    redirect('admin/editpage', 'refresh');
                }
            }
            else
            {
                $this->id = $this->uri->segment(3);
                $data['id'] = $this->id;

                # Get DB data
                $query = $this->page_model->getAllPages($this->id);

                if ($query === FALSE)
                {
                    echo ("query failed");
                    exit();
                }
                if ($query->num_rows() > 0)
                {
                    foreach ($query->result() as $row)
                    {
                        $data['id'] = $this->id;
                        $data['name'] = $row->name;
                        $data['description'] = $row->description;
                        $data['keywords'] = $row->keywords;
                        $data['content'] = $row->content;
                        $data['status'] = $row->status;
                    }
                }
                else
                {
                    echo "This is the last else statement!";
                    exit();
                }
                // send db data to the form
                $this->load->view('admin/editpage', $data);
            }
    }
    
    // Delete Page
    function delete() {
        $this->page_model->delete_page();
        $data['title'] = 'Page Deleted';
        $this->load->view('admin/deletesuccess', $data);    
    }
}
    ?&gt;
#20

[eluser]LuckyFella73[/eluser]
The closing bracket of the class is missing! The last
part of your controller:

Code:
# You have this now:
// Delete Page
function delete() {
    $this->page_model->delete_page();
    $data['title'] = 'Page Deleted';
    $this->load->view('admin/deletesuccess', $data);
}
    
?&gt;

#Has to be this:
// Delete Page
function delete() {
    $this->page_model->delete_page();
    $data['title'] = 'Page Deleted';
    $this->load->view('admin/deletesuccess', $data);
}
  } // this one is missing!  
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB