07-12-2018, 12:22 AM
Before the breakdown the view was returning a string and storing that string in a database. Since its my first time trying a project, a run into a problem where previously it worked, and then after it just decided to stop working.
The Error Message:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: picture
Filename: models/Horse_model.php
Line Number: 23
Backtrace:
File: C:\xampp\htdocs\rusaliite\application\models\Horse_model.php
Line: 23
Function: _error_handler
File: C:\xampp\htdocs\rusaliite\application\controllers\Horse_controller.php
Line: 27
Function: create
File: C:\xampp\htdocs\rusaliite\index.php
Line: 315
Function: require_once
The View:
<div id="body">
<?php echo validation_errors(); ?>
<?php echo form_open_multipart('horse_controller/create'); ?>
<form style="width: 30%;">
<div class="form-group">
<label>Name</label>
<input name="name" class="form-control" maxlength="20">
</div>
<div class="form-group">
<label>Bulgarian Name</label>
<input name="name_bulgarian" class="form-control" maxlength="20">
</div>
<div class="form-group">
<label>Sex</label>
<input name="sex" class="form-control" maxlength="1" placeholder="M or F">
</div>
<div class="form-group">
<label>Stable Number</label>
<input name="stable_no" class="form-control" maxlength="2" type="number">
</div>
<div class="form-group">
<label>Picture</label>
<input name="picture" type="file" class="form-control-file">
</div>
<button type="submit" method="POST" class="btn btn-primary">Submit</button>
</form>
</div>
The Controller:
public function create()
{
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// $config['upload_path'] = './uploads/';
// $config['allowed_types'] = '';
// $config['max_size'] = 0;
// $config['max_width'] = 0;
// $config['max_height'] = 0;
// $this->load->library('upload', $config);
// $this->upload->do_upload('photo');
$data['horses'] = $this->Horse_model->create();
$this->load->view('templates/header');
redirect('horse_controller/index');
$this->load->view('templates/footer');
}
else
{
$this->load->view('templates/header');
$this->load->view('horse/create');
$this->load->view('templates/footer');
}
}
The Model:
public function create()
{
$this->name = $_POST['name'];
$this->name_bulgarian = $_POST['name_bulgarian'];
$this->sex = $_POST['sex'];
$this->stable_no = $_POST['stable_no'];
$this->picture = $_POST['picture'];
$this->db->insert('horse', $this);
}
The Error Message:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: picture
Filename: models/Horse_model.php
Line Number: 23
Backtrace:
File: C:\xampp\htdocs\rusaliite\application\models\Horse_model.php
Line: 23
Function: _error_handler
File: C:\xampp\htdocs\rusaliite\application\controllers\Horse_controller.php
Line: 27
Function: create
File: C:\xampp\htdocs\rusaliite\index.php
Line: 315
Function: require_once
The View:
<div id="body">
<?php echo validation_errors(); ?>
<?php echo form_open_multipart('horse_controller/create'); ?>
<form style="width: 30%;">
<div class="form-group">
<label>Name</label>
<input name="name" class="form-control" maxlength="20">
</div>
<div class="form-group">
<label>Bulgarian Name</label>
<input name="name_bulgarian" class="form-control" maxlength="20">
</div>
<div class="form-group">
<label>Sex</label>
<input name="sex" class="form-control" maxlength="1" placeholder="M or F">
</div>
<div class="form-group">
<label>Stable Number</label>
<input name="stable_no" class="form-control" maxlength="2" type="number">
</div>
<div class="form-group">
<label>Picture</label>
<input name="picture" type="file" class="form-control-file">
</div>
<button type="submit" method="POST" class="btn btn-primary">Submit</button>
</form>
</div>
The Controller:
public function create()
{
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// $config['upload_path'] = './uploads/';
// $config['allowed_types'] = '';
// $config['max_size'] = 0;
// $config['max_width'] = 0;
// $config['max_height'] = 0;
// $this->load->library('upload', $config);
// $this->upload->do_upload('photo');
$data['horses'] = $this->Horse_model->create();
$this->load->view('templates/header');
redirect('horse_controller/index');
$this->load->view('templates/footer');
}
else
{
$this->load->view('templates/header');
$this->load->view('horse/create');
$this->load->view('templates/footer');
}
}
The Model:
public function create()
{
$this->name = $_POST['name'];
$this->name_bulgarian = $_POST['name_bulgarian'];
$this->sex = $_POST['sex'];
$this->stable_no = $_POST['stable_no'];
$this->picture = $_POST['picture'];
$this->db->insert('horse', $this);
}