I inserted data into a table using $this->db->insert(). When the data is inserted successfully, the message should be displayed, and the data should not be re-inserted.
:
public function index($message = '') {
$this->load->template('homePage');
}
public function insert() {
if ($_POST['save']) {
$result = $this->home->insertEntry();
$data['message'] = ($result > 0) ? 'saved' : 'Not';
redirect('HomeController',$data);
}
$this->load->view('homePage');
}
Model:
public function insertEntry()
{
$this->name = $_POST['name'];
$this->email = $_POST['email'];
$this->db->insert('users', $this);
return $this->db->affected_rows();
}
View:
<div class="container sampleForm"><?php
echo isset ($message) ? $message : '';
echo form_open( get_class(get_instance()) . '/insert')
. form_label('id') . form_input('id', isset($query['id']) ? $query['id'] : '', 'class="form-control"') . br()
. form_label('name') . form_input('name', isset($query['name']) ? $query['name'] : '', 'class="form-control"') . br()
. form_label('email') . form_custom_input('email','email', isset($query['email']) ? $query['email'] : '', 'class="form-control"') . br()
. form_submit('save', 'save', 'class="btn btn-primary"')
. form_close();
?> </div>
My problem is that if I can display the status, then the data insert for each else status update will not be displayed.
This should all work in my HomeController.php as a controller, Home.php as a model, and homePage.php as a view file. Not in any other files.
My logic is:
Ex: , , name, m1, m2, m3. , , . . . php.