У меня есть этот код для обновления базы данных, но он не работает. Помогите мне отследить ошибку:
Ошибка находится на проверке, но я не могу найти никаких проблем в своем коде. Возникает эта ошибка: «требуется имя_продукта»
»требуется имя пользователя»
»требуется адрес электронной почты»
»требуется тип пользователя»
и поэтому моя база данных не обновляется. Я только что включил код только для 4 элементов в контроллер и просматриваю
Мой контроллер
function edit_product($product_id) {
$product = $this->generalmod_model->get_product($product_id);
//validate form input
$this->form_validation->set_rules('product_name', 'product_name name', 'required|xss_clean');
$this->form_validation->set_rules('username', 'username', 'required|xss_clean');
$this->form_validation->set_rules('email', 'email', 'required|xss_clean');
$this->form_validation->set_rules('usertype', 'usertype', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
$data = array(
'product_name' => $this->input->post('product_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'usertype' => $this->input->post('usertype'),
);
if ($this->form_validation->run() === true)
{
$this->generalmod_model->update_product($product_id, $data);
echo "updated successfully";
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['product'] = $product;
//display the edit product form
$this->data['product_name'] = array(
'product_name' => 'product_name',
'id' => 'product_name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('product_name', $product['product_name']),
);
$this->data['username'] = array(
'username' => 'username',
'id' => 'username',
'type' => 'text',
'style' => 'width:300px',
'value' => $this->form_validation->set_value('username', $product['username']),
);
$this->data['email'] = array(
'email' => 'email',
'id' => 'email',
'type' => 'text',
'style' => 'width:300px',
'value' => $this->form_validation->set_value('email', $product['email']),
);
$this->data['usertype'] = array(
'usertype' => 'usertype',
'id' => 'usertype',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('usertype', $product['usertype']),
);
$this->load->view('update_profile', $this->data);
}
Моя модель
function get_product($product_id)
{
$this->db->select('user_id, product_name, username, email, usertype');
$this->db->where('user_id', $product_id);
$query = $this->db->get('users');
return $query->row_array();
}
public function update_product($product_id, $data)
{
$this->db->where('user_id', $product_id);
$this->db->update('users', $data);
}
вид:
echo form_open("generalcon/edit_product/$product_id");?>
product Name:
username:
Email:
usertype:
Подробнее здесь: https://stackoverflow.com/questions/232 ... odeigniter
Как обновить базу данных в Codeigniter ⇐ Php
Кемеровские программисты php общаются здесь
1769841068
Anonymous
У меня есть этот код для обновления базы данных, но он не работает. Помогите мне отследить ошибку:
Ошибка находится на проверке, но я не могу найти никаких проблем в своем коде. Возникает эта ошибка: «требуется имя_продукта»
»требуется имя пользователя»
»требуется адрес электронной почты»
»требуется тип пользователя»
и поэтому моя база данных не обновляется. Я только что включил код только для 4 элементов в контроллер и просматриваю
Мой контроллер
function edit_product($product_id) {
$product = $this->generalmod_model->get_product($product_id);
//validate form input
$this->form_validation->set_rules('product_name', 'product_name name', 'required|xss_clean');
$this->form_validation->set_rules('username', 'username', 'required|xss_clean');
$this->form_validation->set_rules('email', 'email', 'required|xss_clean');
$this->form_validation->set_rules('usertype', 'usertype', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
$data = array(
'product_name' => $this->input->post('product_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'usertype' => $this->input->post('usertype'),
);
if ($this->form_validation->run() === true)
{
$this->generalmod_model->update_product($product_id, $data);
echo "updated successfully";
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['product'] = $product;
//display the edit product form
$this->data['product_name'] = array(
'product_name' => 'product_name',
'id' => 'product_name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('product_name', $product['product_name']),
);
$this->data['username'] = array(
'username' => 'username',
'id' => 'username',
'type' => 'text',
'style' => 'width:300px',
'value' => $this->form_validation->set_value('username', $product['username']),
);
$this->data['email'] = array(
'email' => 'email',
'id' => 'email',
'type' => 'text',
'style' => 'width:300px',
'value' => $this->form_validation->set_value('email', $product['email']),
);
$this->data['usertype'] = array(
'usertype' => 'usertype',
'id' => 'usertype',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('usertype', $product['usertype']),
);
$this->load->view('update_profile', $this->data);
}
Моя модель
function get_product($product_id)
{
$this->db->select('user_id, product_name, username, email, usertype');
$this->db->where('user_id', $product_id);
$query = $this->db->get('users');
return $query->row_array();
}
public function update_product($product_id, $data)
{
$this->db->where('user_id', $product_id);
$this->db->update('users', $data);
}
вид:
echo form_open("generalcon/edit_product/$product_id");?>
product Name:
username:
Email:
usertype:
Подробнее здесь: [url]https://stackoverflow.com/questions/23200699/how-to-update-database-in-codeigniter[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия