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

[eluser]the_unforgiven[/eluser]
<?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');

$this->id = $this->uri->segment(3);
$data['id'] = $this->id;

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]');
$this->form_validation->set_rules('description', 'Description', 'trim|required|min_length[3]|max_length[160]');
$this->form_validation->set_rules('keywords', 'Keywords', 'trim|required|min_length[3]|max_length[160]');
$this->form_validation->set_rules('content', 'Content', 'trim|required|min_length[3]|max_length[2000]');



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

$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);
//$query = $this->page_model->update_page($data, $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);
}

}
?>


Messages In This Thread
Help required with update and insert - by El Forum - 08-16-2011, 03:42 AM
Help required with update and insert - by El Forum - 08-16-2011, 05:10 AM
Help required with update and insert - by El Forum - 08-16-2011, 05:23 AM
Help required with update and insert - by El Forum - 08-16-2011, 05:30 AM
Help required with update and insert - by El Forum - 08-16-2011, 05:37 AM
Help required with update and insert - by El Forum - 08-16-2011, 05:40 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:11 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:15 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:31 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:41 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:44 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:50 AM
Help required with update and insert - by El Forum - 08-16-2011, 06:52 AM
Help required with update and insert - by El Forum - 08-16-2011, 07:10 AM
Help required with update and insert - by El Forum - 08-16-2011, 07:16 AM
Help required with update and insert - by El Forum - 08-16-2011, 07:22 AM
Help required with update and insert - by El Forum - 08-16-2011, 07:41 AM
Help required with update and insert - by El Forum - 08-16-2011, 09:16 AM
Help required with update and insert - by El Forum - 08-16-2011, 09:19 AM
Help required with update and insert - by El Forum - 08-16-2011, 09:29 AM
Help required with update and insert - by El Forum - 08-16-2011, 09:31 AM
Help required with update and insert - by El Forum - 08-16-2011, 09:44 AM
Help required with update and insert - by El Forum - 08-16-2011, 09:54 AM
Help required with update and insert - by El Forum - 08-16-2011, 10:03 AM
Help required with update and insert - by El Forum - 08-16-2011, 10:08 AM
Help required with update and insert - by El Forum - 08-16-2011, 10:37 AM
Help required with update and insert - by El Forum - 08-16-2011, 11:41 AM
Help required with update and insert - by El Forum - 08-17-2011, 03:02 AM
Help required with update and insert - by El Forum - 08-17-2011, 05:24 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:08 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:16 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:23 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:33 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:34 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:35 AM
Help required with update and insert - by El Forum - 08-17-2011, 06:42 AM
Help required with update and insert - by El Forum - 08-17-2011, 07:41 AM
Help required with update and insert - by El Forum - 08-17-2011, 07:55 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:00 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:06 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:06 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:07 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:08 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:09 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:10 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:13 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:21 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:24 AM
Help required with update and insert - by El Forum - 08-17-2011, 08:41 AM
Help required with update and insert - by El Forum - 08-17-2011, 10:21 AM
Help required with update and insert - by El Forum - 08-17-2011, 10:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB