My model:
class Admin_model extends CI_Model{
function add_blog($data){
$this->db->insert('blog',$data);
return true;
}
}
My controller function:
function add_blog(){
$this->form_validation->set_rules('heading','Heading', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('error',"Please check the required field");
redirect('admin/dashboard/add');
}else{
//for upload file
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = 'pdf|doc|docx|txt|jpeg|png|ppt';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$image_path = base_url("uploads/".$post['raw_name'].$post['file_ext']);
$data['picture'] = $image_path;
$data_image = array('upload_data' => $this->upload->data());
}
//Upload file end
$data['picture'] = $data_image['upload_data']['file_name'];
$data['heading'] = ucwords($this->input->post('heading'));
$data['description'] = ucfirst($this->input->post('description'));
$data['type_id'] = ucwords($this->input->post('type_id'));
$data['price'] = $this->input->post('price');
$insert_data = $this->admin_model->add_blog($data);
if($insert_data){
echo '<script>alert("Note added sucessfully.");</script>';
redirect('admin/dashboard');
}else{
$this->session->set_flashdata('message',"There is problem in inserting data, please retry once");
echo "error at last ";
redirect('admin/dashboard/add');
}
}
}
My view:
<form role="form" name="myForm" method="post" enctype="multipart/form-data" action="<?php echo site_url('admin/dashboard/add_blog');?>">
<label for="">Category</label>
<select name="type_id" id="" class="form-control" >
<?php
if(count($product_list )>0 ){
foreach ($product_list as $key => $value) {
?>
<option value="<?php echo $value['type_id'];?>"><?php echo $value['type'];?></option>
<?php
}}?>
</select>
<label for=""> Heading </label>
<input type="text" name="heading"class="form-control">
<label for="">Price</label>
<input type="number" name="price" class="form-control">
<label for="">Description</label>
<textarea name="description" id="" cols="30" rows="5" class="form-control"></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">Upload pic</label>
<div class="input-group">
<div class="custom-file">
<!-- <input type="file" name="userfile" class="form-control"> -->
<?php echo form_upload(['name'=>'userfile']); ?>
</div>
</div>
<?php if(isset($upload_error)){echo $upload_error;}?>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data_image
Filename: admin/Dashboard.php
Line Number: 64
Backtrace:
File:
/opt/lampp/htdocs/shremad/application/controllers/admin/Dashboard.php
Line: 64 Function: _error_handler
File: /opt/lampp/htdocs/shremad/index.php Line: 315 Function:
require_once
A PHP Error was encountered
Severity: Notice
Message: Trying to access array offset on value of type null
Filename: admin/Dashboard.php
Line Number: 64
Backtrace:
File:
/opt/lampp/htdocs/shremad/application/controllers/admin/Dashboard.php
Line: 64 Function: _error_handler
File: /opt/lampp/htdocs/shremad/index.php Line: 315 Function:
require_once
A Database Error Occurred
Error Number: 1048
Column 'picture' cannot be null
INSERT INTO blog (picture, heading, description, type_id,
price) VALUES (NULL, 'Djjdjdj', 'Jjdjdj', '1', '')
Filename: models/Admin_model.php
Line Number: 5
Let's analyze the error message first.
Message: Undefined variable: data_image
Which means, somewhere in the code you're calling a variable named "data_image" which is undefined. Now, please notice that this is a NOTICE, so there might be cases that your code would work well BUT it's a bad practice and might cause troubles. (As in your case for instance).
Looking at your code, the following "block":
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$image_path = base_url("uploads/".$post['raw_name'].$post['file_ext']);
$data['picture'] = $image_path;
$data_image = array('upload_data' => $this->upload->data());
}
//Upload file end
$data['picture'] = $data_image['upload_data']['file_name'];
The $data_image variable is defined only under the "else" statement.
So if the condition returns true, the $data_image variable is truly undefined.
In that case, the following command:
$data['picture'] = $data_image['upload_data']['file_name'];
which is based on the $data_image variable, would return another problem:
Message: Trying to access array offset on value of type null
so $data['picture'] now is NULL, which cause your last problem:
Column 'picture' cannot be null
The solution?
Make sure you have a value for $data_image even in the case that the condition returns true. Or, if this condition returns true - handle the things differently. Please also notice that there might be a logical problem with the function in the condition that returns an unexpected result.
(The condition: if ( ! $this->upload->do_upload()))
Related
I am making a news editing feature using CodeIgniter 3, there is also an image edit here
But has errors like the following,
An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function Operator::edit_berita(), 0 passed in D:\xampp\htdocs\ui-desa\system\core\CodeIgniter.php on line 532 and exactly 1 expected
Filename: D:\xampp\htdocs\ui-desa\application\controllers\Operator.php
Line Number: 164
Backtrace:
File: D:\xampp\htdocs\ui-desa\index.php
Line: 315
Function: require_once
Controller Operator.php
public function edit_berita($id_berita)
{
$data['title'] = 'Edit Berita';
$data['user'] = $this->db->get_where(
'user',
['id' => $this->session->userdata('id')],
['email' => $this->session->userdata('email')]
)->row_array();
$data['berita'] = $this->model_berita->getAllBeritaById($id_berita);
// $data['berita'] = $this->db->get('berita')->result_array();
// $data['berita'] = $this->model_berita->getNama();
$this->form_validation->set_rules('judul_berita', 'Judul Berita', 'required');
$this->form_validation->set_rules('isi_berita', 'Isi Berita', 'required');
if ($this->form_validation->run() == false) {
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar', $data);
$this->load->view('templates/topbar', $data);
$this->load->view('operator/editberita', $data);
$this->load->view('templates/footer');
} else {
$judul_berita = $this->input->post('judul_berita');
$slug_berita = url_title($this->input->post('judul_berita'), 'dash', 'TRUE');
$isi_berita = $this->input->post('isi_berita');
$tgl_berita = date('Y-m-d H:i:s');
$id = $this->session->userdata('id');
// Cek Jika Ada Gambar Yang DiUpload
$upload_image = $_FILES['gambar_berita'];
if ($upload_image) {
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['upload_path'] = './gambar_berita/';
$this->load->library('upload', $config);
if ($this->upload->do_upload('gambar_berita')) {
$old_image = $data['berita']['gambar_berita'];
if ($old_image != 'default.jpg') {
unlink(FCPATH . 'gambar_berita/' . $old_image);
}
$new_image = $this->upload->data('file_name');
$this->db->set('gambar_berita', $new_image);
} else {
echo $this->upload->display_errors();
}
}
$this->db->set('id_berita', $id_berita);
$data = array(
'judul_berita' => $judul_berita,
'isi_berita' => $isi_berita
);
$this->db->where($data);
$this->db->update('berita');
$this->session->set_flashdata('message', '<div class="alert alert-success" role ="alert"> Berita Berhasil di Reposting </div>');
redirect('operator/berita');
}
}
Model model_berita.php
public function getAllBeritaById($id_berita)
{
return $this->db->get_where('berita', ['id_berita' => $id_berita])->row_array();
}
View edit_berita.php
<!-- CK Editor 4 -->
<script src="<?= base_url('ckeditor/'); ?>ckeditor.js"></script>
<script src="<?= base_url('ckeditor/'); ?>samples/js/sample.js"></script>
<link href="<?= base_url('ckeditor/'); ?>samples/css/samples.css" rel="stylesheet">
<link href="<?= base_url('ckeditor/'); ?>samples/toolbarconfigurator/lib/codemirror/neo.css" rel="stylesheet">
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">
<?= $title; ?></h1>
<div class="row">
<div class="col-lg">
<?php if (validation_errors()) : ?>
<div class="alert alert-danger" role="alert">
<?= validation_errors(); ?>
</div>
<?php endif; ?>
<?= $this->session->flashdata('message'); ?>
<?= form_open_multipart('operator/edit_berita') ?>
<form action="" method="post">
<input type="hidden" name="id" value="<?= $berita['id_berita']; ?>">
<div class="modal-body">
<div class="form-group">
<small>Masukkan Judul Berita</small>
<input type="text" value="<?= $berita['judul_berita']; ?>" class="form-control" id="judul_berita" name="judul_berita" placeholder="Judul Berita..." required>
</div>
<div class="form-group">
<small>Masukkan Isi Berita</small>
<textarea class="form-control" name="isi_berita" id="editor" required><?= $berita['isi_berita']; ?></textarea>
</div>
<div class="form-group">
<label for="gambar_berita">Ganti Gambar Berita</label>
<div class="col-sm-12">
<div class="row">
<div class="col-sm-3">
<img src="<?= base_url('gambar_berita/') . $berita['gambar_berita']; ?>" class="img-thumbnail" alt="Gambar Berita">
</div>
<div class="col-sm-9">
<div class="custom-file">
<input type="file" class="custom-file-input" id="gambar_berita" name="gambar_berita">
<label class="custom-file-label" for="gambar_berita">Choose File</label>
</div>
</div>
</div>
</div>
<br>
<button type="reset" class="btn btn-danger" data-dismiss="modal">Reset</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
<script>
initSample();
</script>
I've tried a number of ways, but it's still an error too. Please help so that my news update feature can work. Thanks.
Well your error clearly states that your method.
public function edit_berita($id_berita)
is expecting a parameter, which you have named $id_berita.
I cannot tell why you decided to have a parameter in this method, so I can only make some suggestions to help you solve your issue.
From what I can gather from your supplied code you could try the following options...
Option 1:
From what I can tell from your form, you are posting this as a hidden input, so you should be retrieving it from the Post Data.
<input type="hidden" name="id" value="<?= $berita['id_berita']; ?>">
So your method should become...
public function edit_berita()
{
$id_berita = $this->input->post('id'); // This needs to be validated
// The rest of your code below here...
}
But I would be validating that value to see if it exists before processing anything else.
Personally, I would be naming it as id_berita in your form to keep things matched up to avoid mistakes.
Option 2:
Another option would be to modify your form_open_mulitpart from
<?= form_open_multipart('operator/edit_berita') ?>
To include the id to pass in as a parameter
<?= form_open_multipart('operator/edit_berita/'.$berita['id_berita']) ?>
You will have to check that by inspecting your HTML Source using your Browsers "View Source" and inspect the HTML to see that it has ended up in the right place.
That will let you use your existing method
public function edit_berita($id_berita)
But again, you would need to validate that the passed in $id_berita is correct.
Which ever way you go, is your choice. You just need to read through your code and understand it a bit better.
I hope that gives you some guidance.
I have a problem with Codeigniter. I try to pass value from view to controller and it works. But there is a problem when it passing from controller to model. It didn't return any value into View.
Here is my controller:
public function Edit2G() {
$id = $this->uri->segment(3);
$this->load->model("main_model");
$data['fetch_data_2G_where'] = $this->main_model->fetch_data_2G_id($id);
$data['id'] = $id;
$data['title'] = "Update Data 2G";
$this->load->view('templates/header');
$this->load->view("pages/Update2G", $data);
$this->load->view('templates/footer');
}
Here is Model
function fetch_data_2G_id($id)
{
$get_2G_data_stored_proc = "CALL Get_2G_Data(?)";
$data = array( 'id' =>$id);
$query = $this->db->query($get_2G_data_stored_proc, $data);
$result = $query->result_array();
return $get_2G_data_stored_proc;
}
And this is my View
<h2 align="center"><?=$title ?></h2>
<h3 align="center"><?=$id ?></h3>
<p align="center"><?php echo $fetch_data_2G_where['id'];?></p> //This is a test
<?php echo form_open('posts/update'); ?>
<input type="hidden" name="id" value="<?php //echo $fetch_data_2G_where['id']; ?>">
<div class="form-group">
<label>Site ID</label>
<input type="text" class="form-control" name="title" placeholder="add title" value="<?php //echo $fetch_data_2G_where['site_name'];?>">
</div>
This is the stored procedure result
id, id_site, site_name, bsc_name, bcf_id, vlan1, vlan2, status,status_vlan
'1', 'COK008', 'Combat Batylon754','FBTIMIKA-1','BCF-0112', '3677', '3137', '', 'Metro E'
This in Error That I got
A PHP Error was encountered Severity: Warning
Message: Illegal string offset 'id'
Filename: pages/Update2G.php
Line Number: 3
Backtrace:
File: C:\xampp\htdocs\DapotTimika\application\views\pages\Update2G.php
Line: 3 Function: _error_handler
File: C:\xampp\htdocs\DapotTimika\application\controllers\Pages.php
Line: 46 Function: view
File: C:\xampp\htdocs\DapotTimika\index.php Line: 315 Function:
require_once
What I am missing?
PS: the stored procedure only has one parameter (id) to return / get data
in your controller print_r the below line
$data['fetch_data_2G_where'] = $this->main_model->fetch_data_2G_id($id);
echo "<pre>"; print_r($data['fetch_data_2G_where']);
just to see what's the result your query returning. then from your result you can analyse and get the desired results in view.
Thank You Guys for the answer, I found the answer.
I Forgot to parse return value from model into array. The code in model and controller is fine.
here is my view code
<?php
if($fetch_data_2G_where->num_rows() > 0)
{
foreach($fetch_data_2G_where->result_array() as $data)
{
?>
<input type="hidden" name="id" value="<?php echo $data['id']; ?>">
<div class="form-group">
<label>Site ID</label>
<input type="text" class="form-control" name="site_id" value="<?php echo $data['id_site'];?>">
<?php } ?>
Here is the Result
This is my form :
<form method = "POST" action = "<?php echo base_url('Usercontroller/insert') ?>">
<div class="form-group">
<label for="exampleInputEmail1">Apartament</label>
<input type="text" name ="txtApartament" class="form-control" id="txtApartament" placeholder="Apartament">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Status</label>
<select name ="txtStatus" class="form-control">
<?php foreach($getStatus as $value) { ?>
<option value = "<?php echo $value->per_id ?>"><?php echo $value->status_name;?></option>
<?php }?>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Nume</label>
<input type="text" name ="txtNume" class="form-control" id="txtNume" placeholder="Nume">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Persoane</label>
<input type="text" name ="txtPersoane" class="form-control" id="txtPersoane" placeholder="Personae">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Mp</label>
<input type="text" name ="txtMp" class="form-control" id="txtMp" placeholder="Mp">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Comentariu</label>
<input type="text" name ="txtComentariu" class="form-control" id="txtComentariu" placeholder="Comentariu">
</div>
<button type="submit" class="btn btn-default">Salveaza</button>
</form>
And this is my controller insert function side:
public function insert() {
$datai= $this->input->post();
if(isset($datai)){
$txtApartament = $datai['txtApartament'];
$txtStatus = $datai['txtStatus'];
$txtNume = $datai['txtNume'];
$txtPersoane = $datai['txtPersoane'];
$txtMp = $datai['txtMp'];
$txtComentariu = $datai['txtComentariu'];
$this->Usermodel->insertUser($txtApartament,$txtStatus,$txtNume,$txtPersoane,$txtMp,$txtComentariu);
redirect('');
}
}
Model side:
public function insertUser($apartament, $status, $nume, $persoane, $mp, $comentariu){
$arrayDates = array(
'apartament' => $apartament,
'per_id' => $status,
'nume' => $nume,
'persoane' => $persoane,
'mp' => $mp,
'comentariu' => $comentariu
);
$this->db->insert('membri', $arrayDates);
}
When I will submit on my forum I will get this :
A Database Error Occurred
Error Number: 1048
Column 'apartament' cannot be null
INSERT INTO `membri` (`apartament`, `per_id`, `nume`, `persoane`, `mp`, `comentariu`) VALUES (NULL, NULL, NULL, NULL, NULL, NULL)
Filename: models/Usermodel.php
Line Number: 28
Also this:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: txtApartament
Filename: controllers/Usercontroller.php
Line Number: 18
Backtrace:
File: /var/www/html/adminigniter1/application/controllers/Usercontroller.php
Line: 18
Function: _error_handler
File: /var/www/html/adminigniter1/index.php
Line: 315
Function: require_once
When my controller gets the data, will make it NULL, my form is passing the data correctly(checked the headers), what can be the issue on the controller side ?
And yes, I have set the helper with url and form!
I found the solution, wasn't from my code, it was apache2 ...
in the rewrite.load file in apache, I added the line :
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
And it worked!
I have been getting this error while submiting a form using codeigniter. I need help even though I have been following the documentation.
I am using 2.x version of codeigniter
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Products::$input‐
Filename: core/Model.php
Line Number: 52
Fatal error: Call to undefined function post() in /opt/lampp/htdocs/gamingplace/application/models/product_model.php on line 63
This is the code in my model
//add new product
public function addProduct(){
$data = array(
'category_id' => $this->input‐>post('category_id'),
'title' => $this->input‐>post('title'),
'description' => $this->input‐>post('description'),
'price' => $this->input‐>post('price')
);
if($_FILES['image']['error'] == 0){
$data['image'] = $this->upload->file_name;
return $this->db->insert('products',$data);
}
}
}
This is the code in my controller
public function addProduct()
{
if($_FILES['image']['error'] == 0){
//setting image preferences
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'jpg|png|jpeg|PNG|JPEG|JPG';
$config['overwrite'] = false;
$config['quality'] = '100%';
$config['remove_spaces'] = true;
$config['max_size'] = '90';// in KB
$this->load->library('upload',$config);
echo $this->input->post('image');
if( ! $this->upload->do_upload('image'))
{
$this->session->set_flashdata('message_failed', $this->upload->display_errors('', ''));
redirect('dashboard');
}else{
//Image Resizing
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config['maintain_ratio'] = FALSE;
$config['width'] = 311;
$config['height'] = 162;
$this->load->library('image_lib',$config);
if ( ! $this->image_lib->resize()){
$this->session->set_flashdata('message_failed', $this->image_lib->display_errors('', ''));
}
//calling a model an its method to add a new product to the database
if($this->product_model->addProduct()){
$upload_data = $this->upload->data();
$this->session->set_flashdata('message', 'A new product,'. $upload_data['file_name'].'has been added!');
redirect('dashboard');
}
}
}
}
}
And my view
<!-- Modal -->
<script src="<?php echo base_url(); ?>assets/js/validation.js" charset="utf-8"></script>
<div class="modal fade" id="addProduct" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Product</h4> <em>if the product category is not in the select option,
go to add category link to add category before adding this product</em>
</div>
<div class="modal-body">
<?php echo validation_errors('<div class="alert alert-danger">','</div>') ?>
<form role= "form" action="<?php echo base_url()?>products/addProduct" method="post" name="form" onsubmit="return validate(this)" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="title" class="form-control" placeholder="Enter name of product" required>
</div>
<div class="form-group">
<label>Brief Description of Product</label>
<textarea name="description" rows="8" cols="80" class="form-control">
This is a brand made by Gucci Company. Made of cotton, bla bla bla
</textarea>
</div>
<label>Select Category</label>
<div class="form-group">
<select class="form-control" name="category_id">
<?php foreach (get_categories_h() as $popular): ?>
<option value="<?php echo$popular->id?>"><?php echo $popular->name ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label>Enter or choose price</label>
<input type="number" id="price" class="form-control" name="price_old" required>
</div>
<input type="hidden" name="price" class="form-control" id="mainPrice"required>
<div class="form-group">
<input type="file" name="image" id="image" class="form-control" required accept="image/*" onChange="validateImage(this.value)">
</div>
<button type="submit" name="submit" class=" form-control btn btn-success">Add</button>
</form>
</form>
</div>
</div>
</div>
</div>
I think you may have a few issues going on with your code, but let's first focus on your question/error you mentioned. In your controller function, you are not passing the post to the model. You need to do something like this in the controller:
$addProduct = $this->product_model->addProduct($_POST);
if($addProduct){
$upload_data = $this->upload->data();
$this->session->set_flashdata('message', 'A new product,'. $upload_data['file_name'].'has been added!');
redirect('dashboard');
}
In the model function, you need to first let the function know there is an incoming parameter, then adjust how you are assigning the fields to the data array.
public function addProduct($post){
$data = array(
'category_id' => $post["category_id"],
'title' => $post["title"],
'description' => $post["description"],
'price' => $post["price"]
);
return $this->db->insert('products',$data);
}
After that, I noticed that you have some other FILES logic in your model. That will likely error out, too. I believe that is going to have to be done in the controller, not the model. Once you do the upload in the controller, you can pass the file name into the model as well.
$upload_data = $this->upload->data();
$addProduct = $this->product_model->addProduct($_POST, $upload_data['file_name']);
if($addProduct){
$this->session->set_flashdata('message', 'A new product,'. $upload_data['file_name'].'has been added!');
redirect('dashboard');
}
Then, adjust the model.
public function addProduct($post, $fileName){
$data = array(
'category_id' => $post["category_id"],
'title' => $post["title"],
'description' => $post["description"],
'price' => $post["price"],
'image' => $fileName
);
return $this->db->insert('products',$data);
}
Hope this helps.
I have been having a problem... a frustrating problem at that. I cannot seem to edit a specific row in Codeigniter. I have found previous questions on the same here, and even tried the solutions but to no avail. I am press for time on this project I am undertaking. Before you regard this question as a duplicate please have a look see. Any help will be greatly appreciated... Thank you in advance My code snippets are below:
Codeigniter/Controller
<?php..
//Selects all from admin table
function get_admin(){
$data['query'] = $this->Superuser_Model->selectadmin();
}
//brings in the view
// function editAdmin(){
// $data['content'] = 'admin/edit_admin';
// $this->load->view('include/template_back', $data);
// }
//click a specific row in the view (tabulated data)
function edit($id){
$data['array']= $this->Superuser_Model->editadmin($id);
// $data['content'] = 'admin/edit_admin';
$this->load->view('include/header_back');
$this->load->view('admin/edit_admin', $data);
$this->load->view('include/footer_back');
}
//Should update the from
function update_superuser(){
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('password','Password','required');
if($this->form_validation->run()==FALSE)
{
$data['content'] = 'admin/add_admin';
$this->load->view('include/template_back', $data);
}
else
{
$username = $this->input->post('username');
$password = md5($this->input->post('password'));
$date_added = $this->input->post('date_added');
$this->Superuser_Model->update_superuser($username,$password,$date_added);
redirect('login/index', 'refresh');
}
}
..?>
Codeigniter/Model
<?php...
function selectadmin(){
// $id = $this->uri->segment(3);
$query = $this->db->get('admin');
return $query->result_array();
}
function editadmin($id){
$id = $this->uri->segment(3);
$query = $this->db->get('admin');
$this->db->where('adminID', $id);
return $query->result_array();
}
function update_superuser($data, $id){
$this->uri->segment(3);
$id = $this->input->post('adminID');
$data = array(
'username'=> $this->input->post('username'),
'password'=> $this->input->post('password'),
'date_added'=> $this->input->post('date_added')
);
$this->db->where('adminID', $id);
$this->db->update('admin', $data);
}
...?>
Codeigniter/View
...
<?php echo form_open('superuser/update_superuser', array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data')); ?>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
×
−
</div>
<h4 class="panel-title">Admin Details</h4>
<p>Please, Insert your details here below... (for Superuser use only)</p>
</div>
<div class="panel-body panel-body-nopadding">
<!--username-->
<div class="form-group">
<!-- <input type="hidden" name="adminID" class="form-control" value="<?php echo $array->adminID;?>"/> -->
<label class="col-sm-4 control-label">Username</label>
<div class="col-sm-8">
<input type="text" name="username" class="form-control" value="<?php echo $array['username'];?>"/>
</div>
// <?php // form_error('username');?>
</div>
<!--password-->
<div class="form-group">
<label class="col-sm-4 control-label">Password</label>
<div class="col-sm-8">
<input type="password" name="password" class="form-control" value="<?php echo $array['password'];?>"/>
</div>
<?php //echo form_error('date_added');?>
</div>
<!--Date Added-->
<div class="form-group">
<label class="col-sm-4 control-label">Date</label>
<div class="col-sm-8">
<input type="text" name="date_added" class="form-control" id="datepicker" value="<?php echo $array['date_added'];?>" /> <img src="<?php echo base_url();?>components/backend/images/calendar.gif" alt="" /><br /><br />
</div>
<?php //echo form_error('date_added');?>
</div>
</div><!-- panel-body -->
<div class="panel-footer">
<button class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div><!-- panel-footer -->
</div><!-- panel-default -->
<?php form_close();?>
...</body></html>
Errors Displayed
A PHP Error was encountered
Severity: Notice
Message: Undefined index: username
Filename: admin/edit_admin.php
Line Number: 54
A PHP Error was encountered
Severity: Notice
Message: Undefined index: password
Filename: admin/edit_admin.php
Line Number: 62
A PHP Error was encountered
Severity: Notice
Message: Undefined index: date_added
Filename: admin/edit_admin.php
Line Number: 70
Seems like not correct $array['username'], $array['password'] and $array['date_added']. Print out $array first and you'll see what's wrong.
I see a few things... Firstly, you are trying to use the $this->input->post method which is beyond the scope of the model (relevant only to the controller). This is what provides you with the php errors...
Secondly, you are passing the right parameters to the model (minus cleaning them from XSS attacks, notice), but you are accepting different ones, so in the model your function should look something like this
function update_superuser($username, $password, $data_added){
$id = $this->input->post('adminID'); // I believe you should be getting the id from the database/session honestly, much safer in these cases
$data = array(
'username'=> $username,
'password'=> $password,
'date_added'=> $data_added
);
$this->db->where('adminID', $id);
$this->db->update('admin', $data);
}
Hope this helps!
You are passing 3 parameters to your update_superuser() function here
$this->Superuser_Model->update_superuser($username,$password,$date_added);
and your function in your model only takes 2 params:
function update_superuser($data, $id){
$this->uri->segment(3);
$id = $this->input->post('adminID');
$data = array(
'username'=> $this->input->post('username'),
'password'=> $this->input->post('password'),
'date_added'=> $this->input->post('date_added')
);
$this->db->where('adminID', $id);
$this->db->update('admin', $data);
}