Кемеровские программисты php общаются здесь
Anonymous
Codeigniter не может получить значения из формы в базу данных
Сообщение
Anonymous » 24 июл 2024, 02:23
Я новичок в codeigniter и пытаюсь перенести значения еды из формы в базу данных. Вот код контроллера m.
Код: Выделить всё
class Tracking extends CI_Controller {
public $Data = array();
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->language('tracking', $this->config->item('language'));
$this->load->model('tracking_model');
//$data['tracking'] = $results['rows'];
}
/*******************************************************
--- GET THE DEFAULT LIST VIEW --------------------------
*******************************************************/
function index()
{
$this->Data['TrackingArray'] = (array)$this->tracking_model->getTracks();
$this->load->view('tracking_view', $this->Data);
}
/*******************************************************
--- ADD NEW --------------------------------------------
*******************************************************/
function add()
{
if($_SERVER['REQUEST_METHOD']=='POST'){
$this->_validation();
if ($this->form_validation->run() == FALSE)
{
$this->Data = array_merge((array) $this->input->post(), (array) $this->Data);
$this->Data['SysError'] = $this->lang->line('customers_validate_fail');
$this->load->view('Form', $this->Data);
}else{
$Results = $this->tracking_model->addTracks();
$this->session->set_flashdata('SysOk', $this->lang->line('tracking_add_success'));
redirect('tracking', 'refresh');
die();
}
}else{
$this->load->view('Form', $this->Data);
}
}
а вот код моей модели
Код: Выделить всё
function addTracks()
{
$Data['Food'] = $this->input->post('Food');
$Data['Calories'] = $this->input->post('Calories');
$Data['TotalFat'] = $this->input->post('TotalFat');
$Data['DietaryFiber'] = $this->input->post('DietaryFiber');
$Data['ServingSize'] = $this->input->post('ServingSize');
$Data['NumberOfServings'] = $this->input->post('NumberOfServings');
$Data['TotalPoints'] = $this->input->post('TotalPoints');
if($this->db->insert('tracking', $Data))
{
return $this->db->insert_id();
}else{
return FALSE;
}
}
и, наконец, вот мой код для формы
<
Введите информацию о еде
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/17735227/codeigniter-cant-get-values-from-form-to-database[/url]
1721777020
Anonymous
Я новичок в codeigniter и пытаюсь перенести значения еды из формы в базу данных. Вот код контроллера m. [code]class Tracking extends CI_Controller { public $Data = array(); public function __construct() { parent::__construct(); $this->load->helper('form'); $this->load->language('tracking', $this->config->item('language')); $this->load->model('tracking_model'); //$data['tracking'] = $results['rows']; } /******************************************************* --- GET THE DEFAULT LIST VIEW -------------------------- *******************************************************/ function index() { $this->Data['TrackingArray'] = (array)$this->tracking_model->getTracks(); $this->load->view('tracking_view', $this->Data); } /******************************************************* --- ADD NEW -------------------------------------------- *******************************************************/ function add() { if($_SERVER['REQUEST_METHOD']=='POST'){ $this->_validation(); if ($this->form_validation->run() == FALSE) { $this->Data = array_merge((array) $this->input->post(), (array) $this->Data); $this->Data['SysError'] = $this->lang->line('customers_validate_fail'); $this->load->view('Form', $this->Data); }else{ $Results = $this->tracking_model->addTracks(); $this->session->set_flashdata('SysOk', $this->lang->line('tracking_add_success')); redirect('tracking', 'refresh'); die(); } }else{ $this->load->view('Form', $this->Data); } } [/code] а вот код моей модели [code] function addTracks() { $Data['Food'] = $this->input->post('Food'); $Data['Calories'] = $this->input->post('Calories'); $Data['TotalFat'] = $this->input->post('TotalFat'); $Data['DietaryFiber'] = $this->input->post('DietaryFiber'); $Data['ServingSize'] = $this->input->post('ServingSize'); $Data['NumberOfServings'] = $this->input->post('NumberOfServings'); $Data['TotalPoints'] = $this->input->post('TotalPoints'); if($this->db->insert('tracking', $Data)) { return $this->db->insert_id(); }else{ return FALSE; } } [/code] и, наконец, вот мой код для формы < Введите информацию о еде [code] Подробнее здесь: [url]https://stackoverflow.com/questions/17735227/codeigniter-cant-get-values-from-form-to-database[/url]