[eluser]HSKrustofsky[/eluser]
I know there are a ton of posts on this, but cant seem to find one that will help me out. I am relatively new to CI, and need some help. I am creating a site to where the customer can input information in a form, submit it, and it automatically inputs the information in its perspective places.
Well, I got it to where the information can be manually inserted in phpmyadmin, but I am trying to make kind of like an admin panel to make it as easy as possible for the customer.
My problem is one, when I add a new post, it won't redirect me back to the panel view. Two, I have to manually go to the panel view when adding, and then when I do I see that it has added a post with a 0(added on top of the post I initially added). Three, I cannot seem to be able to update information. Can anyone help me? Here is the code I have:
admin_model.php:
Code:
<?php
class Admin_model extends Model {
function Admin() {
parent::Model();
}
function create($data) {
$this->db->insert('data', $data);
return $this->db->insert_id();
}
function retrieve() {
$query = $this->db->get('data');
return $query->result();
}
function update($data) {
$this->db->where('id', $this->uri->segment(3));
$this->db->update('data', $data);
}
function delete() {
$this->db->where('id', $this->uri->segment(3));
$this->db->delete('data');
}
}
admin.php
Code:
<?php
class Admin extends Controller {
function Admin() {
parent::Controller();
}
function index() {
$data = array();
$this->load->model('admin_model');
if($query = $this->admin_model->retrieve()) {
$data['records'] = $query;
}
$data['title'] = "Admin";
$this->load->view('panelview', $data);
}
function create() {
$data = array(
'title' => $this->input->post('title'),
'contents' => $this->input->post('contents')
);
$this->load->model('admin_model');
$this->admin_model->create($data);
$this->load->view('addnews', $data);
}
function delete() {
$this->load->model('admin_model');
$this->admin_model->delete();
$this->index();
}
function update() {
$data = array(
'title' => $this->input->post('title'),
'contents' => $this->input->post('contents')
);
$this->load->model('admin_model');
$this->admin_model->update($data);
$this->load->view('editnews', $data);
}
}
addnews.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset-UTF-8">
</head>
<body>
<h1 align="center">Add News</h1>
<table cellpadding="5px" cellspacing="0" border="1" bordercolor="#000" align="center">
<tr>
<td>
<?= form_open('../admin/create') ?>
<ul>
<li>
<label>Title:</label>
<?= form_input('title') ?>
</li>
<li>
<label>Content:</label>
<?= form_input('contents') ?>
</li>
<li>
<?= form_submit('', 'Submit') ?>
</li>
</ul>
<?= form_close() ?>
</td>
</tr>
</table>
</body>
</html>
editnews.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset-UTF-8">
</head>
<body>
<h1 align="center">Edit News</h1>
<table cellpadding="5px" cellspacing="0" border="1" bordercolor="#000" align="center">
<tr>
<td>
<?php echo form_open('../admin/update'); ?>
<p>
<label for="title">Title:</label>
<input type="text" name="title" id="title" />
</p>
<p>
<label for="contents">Content:</label>
<input type="textarea" name="content" id="contents" />
</p>
<p>
<input type="submit" value="Submit" />
</p>
<?php echo form_close(); ?>
</td>
</tr>
</table>
</body>
</html>
If anyone could help me that would be great.